diff --git a/src/power_grid_model_io/converters/pandapower_converter.py b/src/power_grid_model_io/converters/pandapower_converter.py index 0f7aca75..a7892706 100644 --- a/src/power_grid_model_io/converters/pandapower_converter.py +++ b/src/power_grid_model_io/converters/pandapower_converter.py @@ -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, ) @@ -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 @@ -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: """ diff --git a/tests/conftest.py b/tests/conftest.py index 5db6a751..ca74b95f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 52e59ce7..9531aa08 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -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) diff --git a/tests/unit/converters/test_tabular_converter.py b/tests/unit/converters/test_tabular_converter.py index 80af60e5..efe624b4 100644 --- a/tests/unit/converters/test_tabular_converter.py +++ b/tests/unit/converters/test_tabular_converter.py @@ -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, diff --git a/tests/unit/data_types/test_tabular_data.py b/tests/unit/data_types/test_tabular_data.py index 9e91f378..32d40bcf 100644 --- a/tests/unit/data_types/test_tabular_data.py +++ b/tests/unit/data_types/test_tabular_data.py @@ -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") diff --git a/tests/validation/conftest.py b/tests/validation/conftest.py index 791d3b94..0844e6a6 100644 --- a/tests/validation/conftest.py +++ b/tests/validation/conftest.py @@ -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)