-
-
Notifications
You must be signed in to change notification settings - Fork 145
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 2 commits
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 |
---|---|---|
|
@@ -48,7 +48,7 @@ | |
from pandas._typing import Scalar | ||
|
||
from tests import ( | ||
PD_LTE_22, | ||
PD_LTE_23, | ||
TYPE_CHECKING_INVALID_USAGE, | ||
check, | ||
ensure_clean, | ||
|
@@ -450,7 +450,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 | ||
|
@@ -1541,21 +1541,6 @@ def test_types_groupby() -> None: | |
assert_type(df.groupby(by=["col1", "col2"]).nunique(), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
with pytest_warns_bounded( | ||
FutureWarning, | ||
"(The provided callable <built-in function sum> is currently using|The behavior of DataFrame.sum with)", | ||
upper="2.2.99", | ||
): | ||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns", | ||
upper="2.2.99", | ||
): | ||
if PD_LTE_22: | ||
check( | ||
assert_type(df.groupby(by="col1").apply(sum), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check(assert_type(df.groupby("col1").transform("sum"), pd.DataFrame), pd.DataFrame) | ||
s1 = df.set_index("col1")["col2"] | ||
check(assert_type(s1, pd.Series), pd.Series) | ||
|
@@ -1602,7 +1587,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 +1736,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 +1845,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 +1872,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 +2005,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 +2148,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 +2489,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 +2503,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 +2629,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 +3083,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 +3098,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), | ||
|
@@ -3133,19 +3118,17 @@ def test_frame_stack() -> None: | |
def test_frame_reindex() -> None: | ||
# GH 84 | ||
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2]) | ||
df.reindex([2, 1, 0]) | ||
check(assert_type(df.reindex([2, 1, 0]), pd.DataFrame), pd.DataFrame) | ||
|
||
|
||
def test_frame_reindex_like() -> None: | ||
# GH 84 | ||
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2]) | ||
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0]) | ||
|
||
with pytest_warns_bounded( | ||
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", | ||
lower="2.3.0", | ||
): | ||
check( | ||
assert_type( | ||
|
@@ -3277,7 +3260,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 +3372,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__() | ||
|
@@ -3449,9 +3432,10 @@ def sum_mean(x: pd.DataFrame) -> float: | |
return x.sum().mean() | ||
|
||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
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. keep this at |
||
): | ||
check( | ||
assert_type(df.groupby("col1").apply(sum_mean), pd.Series), | ||
|
@@ -3460,29 +3444,32 @@ def sum_mean(x: pd.DataFrame) -> float: | |
|
||
lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean() | ||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
lower="2.2.99", | ||
upper="2.99.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. keep this at |
||
): | ||
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, | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
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. keep this at |
||
): | ||
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, | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
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. keep this at |
||
): | ||
check( | ||
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame), | ||
|
@@ -3493,9 +3480,10 @@ def sample_to_df(x: pd.DataFrame) -> pd.DataFrame: | |
return x.sample() | ||
|
||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
FutureWarning, | ||
"DataFrameGroupBy.apply operated on the grouping columns.", | ||
upper="2.99", | ||
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. keep this at |
||
): | ||
check( | ||
assert_type( | ||
|
@@ -3769,7 +3757,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 +3860,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( | ||
|
@@ -4384,12 +4372,12 @@ def test_transpose() -> None: | |
df = pd.DataFrame({"a": [1, 1, 2], "b": [4, 5, 6]}) | ||
check(assert_type(df.transpose(), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.transpose(None), pd.DataFrame), pd.DataFrame) | ||
|
||
msg = "The copy keyword is deprecated and will be removed in a future" | ||
with pytest_warns_bounded( | ||
DeprecationWarning, | ||
msg, | ||
lower="2.2.99", | ||
lower="2.3.99", | ||
upper="3.0.0", | ||
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 the |
||
): | ||
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.
This test needs to remain, but use 2
FutureWarning
withupper="2.3.99"
and have a check onPD_LTE_23