Skip to content

Commit 5b80a8e

Browse files
Add support for pandas 2 (#4216)
* Squashed changes * Ignored index * Disabled column checking * Reverted deleted code * Updated pyproject.toml * Replaced version check code
1 parent b398501 commit 5b80a8e

28 files changed

+147
-58
lines changed

.github/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ outputs:
2525
- setuptools ==58.0.4
2626
run:
2727
- numpy >=1.21.0
28-
- pandas >=1.5.0, <2.0.0
28+
- pandas >=1.5.0
2929
- dask >=2022.2.0, !=2022.10.1
3030
- scipy >=1.5.0
3131
- scikit-learn >=1.3.0

core-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
numpy>=1.21.0
2-
pandas>=1.5.0, <2.0.0
2+
pandas>=1.5.0
33
scipy>=1.5.0
44
scikit-learn>=1.3.0
55
scikit-optimize>=0.9.0

docs/source/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release Notes
55
* Updated regression metrics to handle multioutput dataframes as well as single output series :pr:`4233`
66
* Added stacking and unstacking utility functions to work with multiseries data :pr:`4250`
77
* Fixes
8+
* Added support for pandas 2 :pr:`4216`
89
* Changes
910
* Unpinned sktime version :pr:`4214`
1011
* Bumped minimum lightgbm version to 4.0.0 for nullable type handling :pr:`4237`

docs/source/user_guide/timeseries.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,8 @@
996996
" ),\n",
997997
" # Plot prediction intervals\n",
998998
" go.Scatter(\n",
999-
" x=X_forecast_dates[\"Date\"].append(X_forecast_dates[\"Date\"][::-1]),\n",
1000-
" y=y_upper.append(y_lower[::-1]),\n",
999+
" x=pd.concat([X_forecast_dates[\"Date\"], X_forecast_dates[\"Date\"][::-1]]),\n",
1000+
" y=pd.concat([y_upper, y_lower[::-1]]),\n",
10011001
" fill=\"toself\",\n",
10021002
" fillcolor=\"rgba(255,0,0,0.2)\",\n",
10031003
" line=dict(color=\"rgba(255,0,0,0.2)\"),\n",

evalml/model_understanding/visualizations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ def get_linear_coefficients(estimator, features=None):
472472
coef_.name = "Coefficients"
473473
coef_.index = features
474474
coef_ = coef_.sort_values()
475-
coef_ = pd.Series(estimator._component_obj.intercept_, index=["Intercept"]).append(
476-
coef_,
475+
coef_ = pd.concat(
476+
[pd.Series(estimator._component_obj.intercept_, index=["Intercept"]), coef_],
477477
)
478478

479479
return coef_

evalml/pipelines/components/transformers/encoders/onehot_encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def fit(self, X, y=None):
152152
random_state=self._initial_state,
153153
)
154154
value_counts = value_counts.sort_values(
155-
[col],
155+
value_counts.iloc[:, 0].name,
156156
ascending=False,
157157
kind="mergesort",
158158
)

evalml/pipelines/components/transformers/preprocessing/decomposer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def determine_periodicity(
151151
period is detected, returns None.
152152
153153
"""
154-
X, y = cls._handle_nullable_types(cls, X, y)
154+
# Only need to handle nullable types on pandas < 2. Kept for backwards compatibility with pandas 1.x.
155+
if int(pd.__version__.split(".")[0]) < 2:
156+
X, y = cls._handle_nullable_types(cls, X, y)
155157

156158
def _get_rel_max_from_acf(y):
157159
"""Determines the relative maxima of the target's autocorrelation."""

evalml/pipelines/components/transformers/preprocessing/polynomial_decomposer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def inverse_transform(self, y_t: pd.Series) -> tuple[pd.DataFrame, pd.Series]:
267267
index=truncated_y_t.index,
268268
),
269269
)
270-
y = y_in_sample.append(y_out_of_sample)
270+
y = pd.concat([y_in_sample, y_out_of_sample])
271271
y.index = original_index
272272
return y
273273

evalml/pipelines/components/transformers/preprocessing/stl_decomposer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def transform(
245245
index=truncated_y.index,
246246
),
247247
)
248-
y_t = y_in_sample.append(y_out_of_sample)
248+
y_t = pd.concat([y_in_sample, y_out_of_sample])
249249
y_t.index = original_index
250250
return X, y_t
251251

@@ -317,7 +317,7 @@ def inverse_transform(self, y_t: pd.Series) -> tuple[pd.DataFrame, pd.Series]:
317317
index=truncated_y_t.index,
318318
),
319319
)
320-
y = y_in_sample.append(y_out_of_sample)
320+
y = pd.concat([y_in_sample, y_out_of_sample])
321321
y.index = original_index
322322
return y
323323

evalml/preprocessing/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,17 @@ def target_distribution(targets):
184184
185185
Examples:
186186
>>> y = pd.Series([1, 2, 4, 1, 3, 3, 1, 2])
187-
>>> target_distribution(y)
187+
>>> print(target_distribution(y).to_string())
188188
Targets
189189
1 37.50%
190190
2 25.00%
191191
3 25.00%
192192
4 12.50%
193-
dtype: object
194193
>>> y = pd.Series([True, False, False, False, True])
195-
>>> target_distribution(y)
194+
>>> print(target_distribution(y).to_string())
196195
Targets
197196
False 60.00%
198197
True 40.00%
199-
dtype: object
200198
"""
201199
distribution = targets.value_counts() / len(targets)
202200
return distribution.mul(100).apply("{:.2f}%".format).rename_axis("Targets")

0 commit comments

Comments
 (0)