Skip to content

Commit 44c8062

Browse files
authored
pandas 3.0 compatibility (#471)
Make library compatible with pandas 3.0. Closes #469.
1 parent 4b64d8e commit 44c8062

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

petab/v1/conditions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_parametric_overrides(condition_df: pd.DataFrame) -> list[str]:
111111
result = []
112112

113113
for column in constant_parameters:
114-
if np.issubdtype(condition_df[column].dtype, np.number):
114+
if not pd.api.types.is_string_dtype(condition_df[column].dtype):
115115
continue
116116

117117
floatified = condition_df.loc[:, column].apply(core.to_float_if_float)

petab/v1/lint.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def check_condition_df(
129129
)
130130

131131
for column_name in req_cols:
132-
if not np.issubdtype(df[column_name].dtype, np.number):
132+
if pd.api.types.is_string_dtype(df[column_name].dtype):
133133
assert_no_leading_trailing_whitespace(
134134
df[column_name].values, column_name
135135
)
@@ -173,14 +173,14 @@ def check_measurement_df(
173173
_check_df(df, MEASUREMENT_DF_REQUIRED_COLS, "measurement")
174174

175175
for column_name in MEASUREMENT_DF_REQUIRED_COLS:
176-
if not np.issubdtype(df[column_name].dtype, np.number):
176+
if pd.api.types.is_string_dtype(df[column_name].dtype):
177177
assert_no_leading_trailing_whitespace(
178178
df[column_name].values, column_name
179179
)
180180

181181
for column_name in MEASUREMENT_DF_OPTIONAL_COLS:
182-
if column_name in df and not np.issubdtype(
183-
df[column_name].dtype, np.number
182+
if column_name in df and pd.api.types.is_string_dtype(
183+
df[column_name].dtype
184184
):
185185
assert_no_leading_trailing_whitespace(
186186
df[column_name].values, column_name
@@ -243,7 +243,7 @@ def check_parameter_df(
243243
check_ids(df.index.values, kind="parameter")
244244

245245
for column_name in PARAMETER_DF_REQUIRED_COLS[1:]: # 0 is PARAMETER_ID
246-
if not np.issubdtype(df[column_name].dtype, np.number):
246+
if pd.api.types.is_string_dtype(df[column_name].dtype):
247247
assert_no_leading_trailing_whitespace(
248248
df[column_name].values, column_name
249249
)
@@ -304,14 +304,14 @@ def check_observable_df(observable_df: pd.DataFrame) -> None:
304304
check_ids(observable_df.index.values, kind="observable")
305305

306306
for column_name in OBSERVABLE_DF_REQUIRED_COLS[1:]:
307-
if not np.issubdtype(observable_df[column_name].dtype, np.number):
307+
if pd.api.types.is_string_dtype(observable_df[column_name].dtype):
308308
assert_no_leading_trailing_whitespace(
309309
observable_df[column_name].values, column_name
310310
)
311311

312312
for column_name in OBSERVABLE_DF_OPTIONAL_COLS:
313-
if column_name in observable_df and not np.issubdtype(
314-
observable_df[column_name].dtype, np.number
313+
if column_name in observable_df and pd.api.types.is_string_dtype(
314+
observable_df[column_name].dtype
315315
):
316316
assert_no_leading_trailing_whitespace(
317317
observable_df[column_name].values, column_name

petab/v1/visualize/data_overview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_data_per_observable(measurement_df: pd.DataFrame) -> pd.DataFrame:
6969
my_measurements[PREEQUILIBRATION_CONDITION_ID] = (
7070
my_measurements[PREEQUILIBRATION_CONDITION_ID]
7171
.astype("object")
72-
.fillna("", inplace=True)
72+
.fillna("")
7373
)
7474
index.append(PREEQUILIBRATION_CONDITION_ID)
7575

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description = "Parameter estimation tabular data"
1212
requires-python = ">=3.11"
1313
dependencies = [
1414
"numpy>=1.15.1",
15-
"pandas>=1.2.0,<3",
15+
"pandas>=1.2.0",
1616
"python-libsbml>=5.17.0",
1717
"sympy",
1818
"colorama",

tests/v1/test_petab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def test_flatten_timepoint_specific_output_overrides():
508508
)
509509

510510
pd.testing.assert_frame_equal(
511-
problem.observable_df, observable_df_expected
511+
problem.observable_df, observable_df_expected, check_dtype=False
512512
)
513513
pd.testing.assert_frame_equal(
514514
problem.measurement_df, measurement_df_expected

0 commit comments

Comments
 (0)