Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/power_grid_model_io/converters/pandapower_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ def _create_pgm_input_motors(self):
cos_phi = self._get_pp_attr("motor", "cos_phi", expected_type="f8")
valid = np.logical_and(np.not_equal(cos_phi, 0.0), np.isfinite(cos_phi))
q_spec = np.sqrt(
np.power(np.divide(p_spec, cos_phi, where=valid), 2, where=valid, out=None) - p_spec**2,
np.power(np.divide(p_spec, cos_phi, where=valid, out=None), 2, where=valid, out=None) - p_spec**2,
where=valid,
out=None,
)
Expand Down Expand Up @@ -1755,7 +1755,9 @@ def join_currents(table: str, bus_name: str, i_name: str) -> pd.DataFrame:
pp_switches_output.loc[link_ids, "i_ka"] = links["i_from"] * 1e-3
in_ka = self.pp_input_data["switch"]["in_ka"].values
pp_switches_output["loading_percent"] = np.nan
pp_switches_output["loading_percent"] = np.divide(pp_switches_output["i_ka"], in_ka, where=in_ka != 0, out=None)
pp_switches_output["loading_percent"] = np.divide(
pp_switches_output["i_ka"].values, in_ka, where=in_ka != 0, out=None
)

assert "res_switch" not in self.pp_output_data
self.pp_output_data["res_switch"] = pp_switches_output
Expand Down Expand Up @@ -2436,7 +2438,10 @@ def get_individual_switch_states(component: pd.DataFrame, switches: pd.DataFrame
)

# no need to fill na because bool(NaN) == True
return pd.Series(switch_states.astype(bool, copy=False))
if Version(version("pandas")) >= Version("3.0.0"):
return pd.Series(switch_states.astype(bool))
else:
return pd.Series(switch_states.astype(bool, copy=False))

def get_switch_states(self, pp_table: str) -> pd.DataFrame:
"""
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
# SPDX-License-Identifier: MPL-2.0

from contextlib import suppress
from importlib.metadata import version

import pandas as pd
from packaging.version import Version

with suppress(pd.errors.OptionError):
pd.set_option("future.no_silent_downcasting", True)
if Version(version("pandas")) < Version("3.0.0"):
# Opt-in to Pandas 3 behavior for Pandas 2.x
with suppress(pd.errors.OptionError):
pd.set_option("future.no_silent_downcasting", True)
9 changes: 6 additions & 3 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
# SPDX-License-Identifier: MPL-2.0

from contextlib import suppress
from importlib.metadata import version

import pandas as pd
from packaging.version import Version

with suppress(pd.errors.OptionError):
# TODO(mgovers) We're ready for Pandas 3.x, but pandapower is not. Move to parent conftest when it is.
pd.set_option("mode.copy_on_write", True)
if Version(version("pandas")) < Version("3.0.0"):
# Opt-in to Pandas 3 behavior for Pandas 2.x
with suppress(pd.errors.OptionError):
pd.set_option("mode.copy_on_write", True)
2 changes: 1 addition & 1 deletion tests/unit/converters/test_tabular_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_convert_col_def_to_attribute(
with pytest.raises(
ValueError,
match=r"DataFrame for ComponentType.node.u_rated should contain a single column "
r"\(Index\(\['id_number', 'u_nom'\], dtype='object'\)\)",
r"\(Index\(\['id_number', 'u_nom'\], dtype='(str|object)'\)\)",
):
converter._convert_col_def_to_attribute(
data=tabular_data_no_units_no_substitutions,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/data_types/test_tabular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_get_column__sanity_check(mock_unit_conversion: MagicMock, nodes_iso: pd
mock_unit_conversion.return_value = nodes_iso["u_rated"]

# Act / Assert
with pytest.raises(TypeError, match=r"u_rated.+unitless.+V"):
with pytest.raises(TypeError, match=r"u_rated[\s\S]*unitless[\s\S]*V"):
data.get_column(table_name="nodes", column_name="u_rated")


Expand Down
13 changes: 8 additions & 5 deletions tests/validation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# SPDX-License-Identifier: MPL-2.0

from contextlib import suppress
from importlib.metadata import version

import pandas as pd
from packaging.version import Version

with suppress(pd.errors.OptionError):
pd.set_option("future.no_silent_downcasting", True)
if Version(version("pandas")) < Version("3.0.0"):
# Opt-in to Pandas 3 behavior for Pandas 2.x
with suppress(pd.errors.OptionError):
pd.set_option("future.no_silent_downcasting", True)

with suppress(pd.errors.OptionError):
# TODO(mgovers) We're ready for Pandas 3.x, but pandapower is not. Move to parent conftest when it is.
pd.set_option("mode.copy_on_write", False)
with suppress(pd.errors.OptionError):
pd.set_option("mode.copy_on_write", False)
Loading