Skip to content

Commit

Permalink
Restore nightly CI build due to new pandas version (3.0.0) (#974)
Browse files Browse the repository at this point in the history
* GH 927 Allow 'integer' in select_dtypes include argument

* TypeGuard clean up in dtypes/missing.pyi

* PR Feedback

* Restore pandas nightly CI build

* Correct freq in test
  • Loading branch information
loicdiridollou authored Aug 7, 2024
1 parent 1896191 commit b3967c9
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 26 deletions.
59 changes: 51 additions & 8 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,13 @@ def test_types_to_html() -> None:
def test_types_resample() -> None:
df = pd.DataFrame({"values": [2, 11, 3, 13, 14, 18, 17, 19]})
df["date"] = pd.date_range("01/01/2018", periods=8, freq="W")
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
df.resample("M", on="date")
df.resample("20min", origin="epoch", offset=pd.Timedelta(2, "minutes"), on="date")
df.resample("20min", origin="epoch", offset=datetime.timedelta(2), on="date")
Expand Down Expand Up @@ -1583,8 +1589,14 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame:
assert isinstance(resampler, Resampler)
return pd.DataFrame(resampler)

with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
val = (
with pytest_warns_bounded(
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
(
pd.DataFrame(
{
"price": [10, 11, 9, 13, 14, 18, 17, 19],
Expand All @@ -1596,6 +1608,18 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame:
.pipe(resampler_foo)
)

val = (
pd.DataFrame(
{
"price": [10, 11, 9, 13, 14, 18, 17, 19],
"volume": [50, 60, 40, 100, 50, 100, 40, 50],
}
)
.assign(week_starting=pd.date_range("01/01/2018", periods=8, freq="W"))
.resample("MS", on="week_starting")
.pipe(resampler_foo)
)

def foo(df: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame(df)

Expand Down Expand Up @@ -1854,11 +1878,22 @@ def test_types_regressions() -> None:
d: datetime.date = pd.Timestamp("2021-01-01")
tslist: list[pd.Timestamp] = list(pd.to_datetime(["2022-01-01", "2022-01-02"]))
sseries: pd.Series = pd.Series(tslist)
sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "d")
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"):
sseries + pd.Timedelta(1, "d")

sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "D")

# https://github.com/microsoft/pylance-release/issues/2133
with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
dr = pd.date_range(start="2021-12-01", periods=24, freq="H")
with pytest_warns_bounded(
FutureWarning,
"'H' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
pd.date_range(start="2021-12-01", periods=24, freq="H")

dr = pd.date_range(start="2021-12-01", periods=24, freq="h")
time = dr.strftime("%H:%M:%S")

# https://github.com/microsoft/python-type-stubs/issues/115
Expand Down Expand Up @@ -2885,8 +2920,16 @@ def test_quantile_150_changes() -> None:
def test_resample_150_changes() -> None:
idx = pd.date_range("2020-1-1", periods=700)
frame = pd.DataFrame(np.random.standard_normal((700, 1)), index=idx, columns=["a"])
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
resampler = frame.resample("M", group_keys=True)
with pytest_warns_bounded(
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
frame.resample("M", group_keys=True)

resampler = frame.resample("MS", group_keys=True)
check(
assert_type(resampler, "DatetimeIndexResampler[pd.DataFrame]"),
DatetimeIndexResampler,
Expand Down
31 changes: 26 additions & 5 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ def test_interval_range():
pd.IntervalIndex,
pd.Interval,
)
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
check(
assert_type(
pd.interval_range(
Expand Down Expand Up @@ -577,9 +583,18 @@ def test_interval_index_arrays():
pd.IntervalIndex,
pd.Interval,
)
with pytest_warns_bounded(FutureWarning, "'Y' is deprecated", lower="2.1.99"):
left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y"))
right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y"))
with pytest_warns_bounded(
FutureWarning,
"'Y' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y"))
pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y"))

left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="YS"))
right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="YS"))
check(
assert_type(
pd.IntervalIndex.from_arrays(left_s_ts, right_s_ts),
Expand Down Expand Up @@ -989,7 +1004,13 @@ def test_index_constructors():

def test_iter() -> None:
# GH 723
with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'H' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
for ts in pd.date_range(start="1/1/2023", end="1/08/2023", freq="6H"):
check(assert_type(ts, pd.Timestamp), pd.Timestamp)

Expand Down
16 changes: 14 additions & 2 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,13 @@ def g(x: pd.Series) -> int:
},
index=idx,
)
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
check(
assert_type(
pd.pivot_table(
Expand All @@ -1990,7 +1996,13 @@ def g(x: pd.Series) -> int:
),
pd.DataFrame,
)
with pytest_warns_bounded(FutureWarning, "'(M|A)' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'(M|A)' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
check(
assert_type(
pd.pivot_table(
Expand Down
36 changes: 29 additions & 7 deletions tests/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,11 @@ def test_interval_cmp():

def test_timedelta_construction() -> None:
check(assert_type(pd.Timedelta(1, "W"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta(1, "w"), pd.Timedelta), pd.Timedelta)
with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"):
check(assert_type(pd.Timedelta(1, "w"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta(1, "D"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta(1, "d"), pd.Timedelta), pd.Timedelta)
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"):
check(assert_type(pd.Timedelta(1, "d"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta(1, "days"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta(1, "day"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta(1, "hours"), pd.Timedelta), pd.Timedelta)
Expand Down Expand Up @@ -421,9 +423,11 @@ def test_timedelta_construction() -> None:
check(assert_type(pd.Timedelta(1, "nanosecond"), pd.Timedelta), pd.Timedelta)

check(assert_type(pd.Timedelta("1 W"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta("1 w"), pd.Timedelta), pd.Timedelta)
with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"):
check(assert_type(pd.Timedelta("1 w"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta("1 D"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta("1 d"), pd.Timedelta), pd.Timedelta)
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"):
check(assert_type(pd.Timedelta("1 d"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta("1 days"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta("1 day"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.Timedelta("1 hours"), pd.Timedelta), pd.Timedelta)
Expand Down Expand Up @@ -1518,7 +1522,13 @@ def test_timestamp_misc_methods() -> None:
check(assert_type(ts2.round("1s", ambiguous=False), pd.Timestamp), pd.Timestamp)
check(assert_type(ts2.round("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp)

with pytest_warns_bounded(FutureWarning, "'H' is deprecated ", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'H' is deprecated ",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
check(
assert_type(ts2.round("2H", nonexistent="shift_forward"), pd.Timestamp),
pd.Timestamp,
Expand Down Expand Up @@ -1553,7 +1563,13 @@ def test_timestamp_misc_methods() -> None:
check(assert_type(ts2.ceil("1s", ambiguous=False), pd.Timestamp), pd.Timestamp)
check(assert_type(ts2.ceil("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp)

with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'H' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
check(
assert_type(ts2.ceil("2H", nonexistent="shift_forward"), pd.Timestamp),
pd.Timestamp,
Expand Down Expand Up @@ -1587,7 +1603,13 @@ def test_timestamp_misc_methods() -> None:
check(assert_type(ts2.floor("1s", ambiguous=False), pd.Timestamp), pd.Timestamp)
check(assert_type(ts2.floor("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp)

with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
with pytest_warns_bounded(
FutureWarning,
"'H' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper_exception=ValueError,
):
check(
assert_type(ts2.floor("2H", nonexistent="shift_forward"), pd.Timestamp),
pd.Timestamp,
Expand Down
8 changes: 5 additions & 3 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,13 @@ def test_types_to_numpy() -> None:
check(assert_type(td_s.to_numpy(na_value=pd.Timedelta(0)), np.ndarray), np.ndarray)


def test_to_timdelta_units() -> None:
def test_to_timedelta_units() -> None:
check(assert_type(pd.to_timedelta(1, "W"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.to_timedelta(1, "w"), pd.Timedelta), pd.Timedelta)
with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"):
check(assert_type(pd.to_timedelta(1, "w"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.to_timedelta(1, "D"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.to_timedelta(1, "d"), pd.Timedelta), pd.Timedelta)
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"):
check(assert_type(pd.to_timedelta(1, "d"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.to_timedelta(1, "days"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.to_timedelta(1, "day"), pd.Timedelta), pd.Timedelta)
check(assert_type(pd.to_timedelta(1, "hours"), pd.Timedelta), pd.Timedelta)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from tests import (
NUMPY20,
PD_LTE_22,
check,
pytest_warns_bounded,
)
Expand All @@ -23,7 +24,7 @@ def test_show_version():
version_str=platform.python_version(),
):
context: AbstractContextManager
if NUMPY20: # https://github.com/PyTables/PyTables/issues/1172
if PD_LTE_22 and NUMPY20: # https://github.com/PyTables/PyTables/issues/1172
context = pytest.raises(ValueError)
else:
context = nullcontext()
Expand Down

0 comments on commit b3967c9

Please sign in to comment.