-
-
Notifications
You must be signed in to change notification settings - Fork 144
GH1246 Upgrade to pandas 2.3.0 #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
|
||
from tests import ( | ||
PD_LTE_22, | ||
PD_LTE_23, | ||
TYPE_CHECKING_INVALID_USAGE, | ||
check, | ||
ensure_clean, | ||
|
@@ -450,7 +451,7 @@ def test_types_drop_duplicates() -> None: | |
pd.DataFrame, | ||
) | ||
|
||
if not PD_LTE_22: | ||
if not PD_LTE_23: | ||
check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame) | ||
check( | ||
assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame | ||
|
@@ -1602,7 +1603,7 @@ def wrapped_min(x: Any) -> Any: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
r"The provided callable <built-in function (min|max)> is currently using", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
check(assert_type(df.groupby("col1")["col3"].agg(min), pd.Series), pd.Series) | ||
check( | ||
|
@@ -1751,7 +1752,7 @@ def test_types_window() -> None: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
r"The provided callable <built-in function (min|max)> is currently using", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
check( | ||
assert_type(df.rolling(2).agg(max), pd.DataFrame), | ||
|
@@ -1860,7 +1861,7 @@ def test_types_agg() -> None: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
r"The provided callable <(built-in function (min|max|mean)|function mean at 0x\w+)> is currently using", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
check(assert_type(df.agg(min), pd.Series), pd.Series) | ||
check(assert_type(df.agg([min, max]), pd.DataFrame), pd.DataFrame) | ||
|
@@ -1887,7 +1888,7 @@ def test_types_aggregate() -> None: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
r"The provided callable <built-in function (min|max)> is currently using", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
check(assert_type(df.aggregate(min), pd.Series), pd.Series) | ||
check(assert_type(df.aggregate([min, max]), pd.DataFrame), pd.DataFrame) | ||
|
@@ -2020,7 +2021,7 @@ def test_types_resample() -> None: | |
FutureWarning, | ||
"'M' is deprecated", | ||
lower="2.1.99", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
upper_exception=ValueError, | ||
): | ||
df.resample("M", on="date") | ||
|
@@ -2163,7 +2164,7 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: | |
FutureWarning, | ||
"'M' is deprecated", | ||
lower="2.1.99", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
upper_exception=ValueError, | ||
): | ||
( | ||
|
@@ -2504,7 +2505,7 @@ def test_types_regressions() -> None: | |
tslist = list(pd.to_datetime(["2022-01-01", "2022-01-02"])) | ||
check(assert_type(tslist, list[pd.Timestamp]), list, pd.Timestamp) | ||
sseries = pd.Series(tslist) | ||
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): | ||
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.3.99"): | ||
sseries + pd.Timedelta(1, "d") | ||
|
||
check( | ||
|
@@ -2518,7 +2519,7 @@ def test_types_regressions() -> None: | |
FutureWarning, | ||
"'H' is deprecated", | ||
lower="2.1.99", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
upper_exception=ValueError, | ||
): | ||
pd.date_range(start="2021-12-01", periods=24, freq="H") | ||
|
@@ -2644,7 +2645,7 @@ class ReadCsvKwargs(TypedDict): | |
), | ||
pd.DataFrame, | ||
) | ||
if PD_LTE_22: | ||
if PD_LTE_23: | ||
parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]} | ||
with pytest_warns_bounded( | ||
FutureWarning, | ||
|
@@ -3098,7 +3099,7 @@ def test_frame_stack() -> None: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
"The previous implementation of stack is deprecated", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
check( | ||
assert_type( | ||
|
@@ -3113,7 +3114,7 @@ def test_frame_stack() -> None: | |
), | ||
pd.Series, | ||
) | ||
if PD_LTE_22: | ||
if PD_LTE_23: | ||
check( | ||
assert_type( | ||
df_multi_level_cols2.stack(0, future_stack=False), | ||
|
@@ -3145,7 +3146,7 @@ def test_frame_reindex_like() -> None: | |
FutureWarning, | ||
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", | ||
lower="2.2.99", | ||
upper="3.0.99", | ||
upper="2.2.99", | ||
): | ||
check( | ||
assert_type( | ||
|
@@ -3277,7 +3278,7 @@ def test_groupby_result() -> None: | |
index, value = next(iterator) | ||
assert_type((index, value), tuple[tuple, pd.DataFrame]) | ||
|
||
if PD_LTE_22: | ||
if PD_LTE_23: | ||
check(assert_type(index, tuple), tuple, np.integer) | ||
else: | ||
check(assert_type(index, tuple), tuple, int) | ||
|
@@ -3389,7 +3390,7 @@ def test_groupby_result_for_ambiguous_indexes() -> None: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
"The default of observed=False is deprecated", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
categorical_index = pd.CategoricalIndex(df.a) | ||
iterator2 = df.groupby(categorical_index).__iter__() | ||
|
@@ -3448,41 +3449,72 @@ def test_groupby_apply() -> None: | |
def sum_mean(x: pd.DataFrame) -> float: | ||
return x.sum().mean() | ||
|
||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
with ( | ||
pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.2.99", | ||
), | ||
pytest_warns_bounded( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite annoying that they changed the type of warning that was raised but guess we don't have too much choice than doubling the context manager to grab the warnings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are testing with 2.3, so you only need to test for |
||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
lower="2.2.99", | ||
upper="2.3.99", | ||
), | ||
): | ||
check( | ||
assert_type(df.groupby("col1").apply(sum_mean), pd.Series), | ||
pd.Series, | ||
) | ||
|
||
lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean() | ||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
with ( | ||
pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.2.99", | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this |
||
pytest_warns_bounded( | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
lower="2.2.99", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to 2.3.99 |
||
), | ||
): | ||
check(assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series) | ||
|
||
def sum_to_list(x: pd.DataFrame) -> list: | ||
return x.sum().tolist() | ||
|
||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
with ( | ||
pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.2.99", | ||
), | ||
pytest_warns_bounded( | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
lower="2.2.99", | ||
upper="2.3.99", | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment - just leave in the 2.3 test since that is all we are testing against |
||
): | ||
check(assert_type(df.groupby("col1").apply(sum_to_list), pd.Series), pd.Series) | ||
|
||
def sum_to_series(x: pd.DataFrame) -> pd.Series: | ||
return x.sum() | ||
|
||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
with ( | ||
pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.2.99", | ||
), | ||
pytest_warns_bounded( | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
lower="2.2.99", | ||
upper="2.3.99", | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
): | ||
check( | ||
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame), | ||
|
@@ -3492,10 +3524,18 @@ def sum_to_series(x: pd.DataFrame) -> pd.Series: | |
def sample_to_df(x: pd.DataFrame) -> pd.DataFrame: | ||
return x.sample() | ||
|
||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
with ( | ||
pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.2.99", | ||
), | ||
pytest_warns_bounded( | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
lower="2.2.99", | ||
upper="2.3.99", | ||
), | ||
): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
check( | ||
assert_type( | ||
|
@@ -3769,7 +3809,7 @@ def test_resample_150_changes() -> None: | |
FutureWarning, | ||
"'M' is deprecated", | ||
lower="2.1.99", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
upper_exception=ValueError, | ||
): | ||
frame.resample("M", group_keys=True) | ||
|
@@ -3872,7 +3912,7 @@ def test_getattr_and_dataframe_groupby() -> None: | |
with pytest_warns_bounded( | ||
FutureWarning, | ||
r"The provided callable <built-in function (min|max)> is currently using", | ||
upper="2.2.99", | ||
upper="2.3.99", | ||
): | ||
check(assert_type(df.groupby("col1").col3.agg(min), pd.Series), pd.Series) | ||
check( | ||
|
@@ -4390,6 +4430,7 @@ def test_transpose() -> None: | |
DeprecationWarning, | ||
msg, | ||
lower="2.2.99", | ||
upper="2.2.99", | ||
): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since no warning is issued with 2.3, we can just leave out the context manager |
||
check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should remove the
PD_LTE_22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!