Skip to content

Commit 536db83

Browse files
authored
fix pyright and pytest --nightly (#819)
* fix pyright and pytest --nightly * catch all FutureWarnings * pandas bug?
1 parent 94df875 commit 536db83

File tree

10 files changed

+253
-137
lines changed

10 files changed

+253
-137
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ ci:
33
autofix_prs: false
44
repos:
55
- repo: https://github.com/python/black
6-
rev: 23.10.0
6+
rev: 23.11.0
77
hooks:
88
- id: black
99
- repo: https://github.com/PyCQA/isort
1010
rev: 5.12.0
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.1.1
14+
rev: v0.1.6
1515
hooks:
1616
- id: ruff
1717
args: [

pandas-stubs/core/indexes/multi.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class MultiIndex(Index[Any]):
153153
def equals(self, other) -> bool: ...
154154
def equal_levels(self, other): ...
155155
def union(self, other, sort=...): ...
156-
def intersection(self, other, sort: bool = ...): ...
156+
def intersection(self, other: list | Self, sort: bool = ...): ...
157157
def difference(self, other, sort=...): ...
158158
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Self: ...
159159
def insert(self, loc, item): ...

scripts/test/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ def pytest(nightly: bool) -> None:
5252
setup_steps = []
5353
pytest_step = _step.pytest
5454
if nightly:
55-
pytest_step = dataclasses.replace(
56-
_step.pytest, run=partial(_step.pytest.run, flags=())
57-
)
5855
setup_steps = [_step.nightly]
5956
run_job(setup_steps + [pytest_step])
6057

tests/test_api_types.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,18 @@ def test_is_integer_dtype() -> None:
246246

247247

248248
def test_is_interval() -> None:
249-
check(assert_type(api.is_interval(obj), bool), bool)
250-
check(assert_type(api.is_interval(nparr), bool), bool)
251-
check(assert_type(api.is_interval(dtylike), bool), bool)
252-
check(assert_type(api.is_interval(arr), bool), bool)
253-
check(
254-
assert_type(api.is_interval(dframe), bool),
255-
bool,
256-
)
257-
check(assert_type(api.is_interval(ind), bool), bool)
249+
with pytest_warns_bounded(
250+
FutureWarning, "is_interval is deprecated", lower="2.1.99"
251+
):
252+
check(assert_type(api.is_interval(obj), bool), bool)
253+
check(assert_type(api.is_interval(nparr), bool), bool)
254+
check(assert_type(api.is_interval(dtylike), bool), bool)
255+
check(assert_type(api.is_interval(arr), bool), bool)
256+
check(
257+
assert_type(api.is_interval(dframe), bool),
258+
bool,
259+
)
260+
check(assert_type(api.is_interval(ind), bool), bool)
258261

259262

260263
def test_is_interval_dtype() -> None:

tests/test_frame.py

+28-19
Original file line numberDiff line numberDiff line change
@@ -1307,9 +1307,8 @@ def test_types_to_html() -> None:
13071307
def test_types_resample() -> None:
13081308
df = pd.DataFrame({"values": [2, 11, 3, 13, 14, 18, 17, 19]})
13091309
df["date"] = pd.date_range("01/01/2018", periods=8, freq="W")
1310-
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
1310+
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
13111311
df.resample("M", on="date")
1312-
# origin and offset params added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
13131312
df.resample("20min", origin="epoch", offset=pd.Timedelta(2, "minutes"), on="date")
13141313

13151314

@@ -1352,7 +1351,7 @@ def test_pipe() -> None:
13521351
def foo(df: pd.DataFrame) -> pd.DataFrame:
13531352
return pd.DataFrame(df)
13541353

1355-
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
1354+
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
13561355
val = (
13571356
pd.DataFrame(
13581357
{
@@ -1521,7 +1520,8 @@ def test_types_regressions() -> None:
15211520
sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "d")
15221521

15231522
# https://github.com/microsoft/pylance-release/issues/2133
1524-
dr = pd.date_range(start="2021-12-01", periods=24, freq="H")
1523+
with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
1524+
dr = pd.date_range(start="2021-12-01", periods=24, freq="H")
15251525
time = dr.strftime("%H:%M:%S")
15261526

15271527
# https://github.com/microsoft/python-type-stubs/issues/115
@@ -1906,18 +1906,24 @@ def test_frame_stack() -> None:
19061906
[[1.0, 2.0], [3.0, 4.0]], index=["cat", "dog"], columns=multicol2
19071907
)
19081908

1909-
check(
1910-
assert_type(
1911-
df_multi_level_cols2.stack(0), Union[pd.DataFrame, "pd.Series[Any]"]
1912-
),
1913-
pd.DataFrame,
1914-
)
1915-
check(
1916-
assert_type(
1917-
df_multi_level_cols2.stack([0, 1]), Union[pd.DataFrame, "pd.Series[Any]"]
1918-
),
1919-
pd.Series,
1920-
)
1909+
with pytest_warns_bounded(
1910+
FutureWarning,
1911+
"The previous implementation of stack is deprecated",
1912+
lower="2.1.99",
1913+
):
1914+
check(
1915+
assert_type(
1916+
df_multi_level_cols2.stack(0), Union[pd.DataFrame, "pd.Series[Any]"]
1917+
),
1918+
pd.DataFrame,
1919+
)
1920+
check(
1921+
assert_type(
1922+
df_multi_level_cols2.stack([0, 1]),
1923+
Union[pd.DataFrame, "pd.Series[Any]"],
1924+
),
1925+
pd.Series,
1926+
)
19211927

19221928

19231929
def test_frame_reindex() -> None:
@@ -2491,7 +2497,7 @@ def test_quantile_150_changes() -> None:
24912497
def test_resample_150_changes() -> None:
24922498
idx = pd.date_range("2020-1-1", periods=700)
24932499
frame = pd.DataFrame(np.random.standard_normal((700, 1)), index=idx, columns=["a"])
2494-
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
2500+
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
24952501
resampler = frame.resample("M", group_keys=True)
24962502
assert_type(resampler, "Resampler[pd.DataFrame]")
24972503

@@ -2858,8 +2864,11 @@ def test_interpolate_inplace() -> None:
28582864
def test_groupby_fillna_inplace() -> None:
28592865
# GH 691
28602866
groupby = pd.DataFrame({"a": range(3), "b": range(3)}).groupby("a")
2861-
check(assert_type(groupby.fillna(0), pd.DataFrame), pd.DataFrame)
2862-
check(assert_type(groupby.fillna(0, inplace=False), pd.DataFrame), pd.DataFrame)
2867+
with pytest_warns_bounded(
2868+
FutureWarning, "DataFrameGroupBy.fillna is deprecated", lower="2.1.99"
2869+
):
2870+
check(assert_type(groupby.fillna(0), pd.DataFrame), pd.DataFrame)
2871+
check(assert_type(groupby.fillna(0, inplace=False), pd.DataFrame), pd.DataFrame)
28632872
if TYPE_CHECKING_INVALID_USAGE:
28642873
groupby.fillna(0, inplace=True) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
28652874

tests/test_indexes.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def test_interval_range():
252252
pd.IntervalIndex,
253253
pd.Interval,
254254
)
255-
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
255+
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
256256
check(
257257
assert_type(
258258
pd.interval_range(
@@ -570,8 +570,9 @@ def test_interval_index_arrays():
570570
pd.IntervalIndex,
571571
pd.Interval,
572572
)
573-
left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y"))
574-
right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y"))
573+
with pytest_warns_bounded(FutureWarning, "'Y' is deprecated", lower="2.1.99"):
574+
left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y"))
575+
right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y"))
575576
check(
576577
assert_type(
577578
pd.IntervalIndex.from_arrays(left_s_ts, right_s_ts),
@@ -968,8 +969,9 @@ def test_index_constructors():
968969

969970
def test_iter() -> None:
970971
# GH 723
971-
for ts in pd.date_range(start="1/1/2023", end="1/08/2023", freq="6H"):
972-
check(assert_type(ts, pd.Timestamp), pd.Timestamp)
972+
with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
973+
for ts in pd.date_range(start="1/1/2023", end="1/08/2023", freq="6H"):
974+
check(assert_type(ts, pd.Timestamp), pd.Timestamp)
973975

974976

975977
def test_intersection() -> None:

tests/test_io.py

+80-23
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,25 @@
7575
def test_orc():
7676
with ensure_clean() as path:
7777
check(assert_type(DF.to_orc(path), None), type(None))
78-
check(assert_type(read_orc(path), DataFrame), DataFrame)
78+
with pytest_warns_bounded(
79+
DeprecationWarning,
80+
"Passing a BlockManager to DataFrame is deprecated",
81+
lower="2.1.99",
82+
):
83+
check(assert_type(read_orc(path), DataFrame), DataFrame)
7984

8085

8186
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
8287
def test_orc_path():
8388
with ensure_clean() as path:
8489
pathlib_path = Path(path)
8590
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
86-
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)
91+
with pytest_warns_bounded(
92+
DeprecationWarning,
93+
"Passing a BlockManager to DataFrame is deprecated",
94+
lower="2.1.99",
95+
):
96+
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)
8797

8898

8999
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
@@ -93,14 +103,24 @@ def test_orc_buffer():
93103
check(assert_type(DF.to_orc(file_w), None), type(None))
94104

95105
with open(path, "rb") as file_r:
96-
check(assert_type(read_orc(file_r), DataFrame), DataFrame)
106+
with pytest_warns_bounded(
107+
DeprecationWarning,
108+
"Passing a BlockManager to DataFrame is deprecated",
109+
lower="2.1.99",
110+
):
111+
check(assert_type(read_orc(file_r), DataFrame), DataFrame)
97112

98113

99114
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
100115
def test_orc_columns():
101116
with ensure_clean() as path:
102117
check(assert_type(DF.to_orc(path, index=False), None), type(None))
103-
check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame)
118+
with pytest_warns_bounded(
119+
DeprecationWarning,
120+
"Passing a BlockManager to DataFrame is deprecated",
121+
lower="2.1.99",
122+
):
123+
check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame)
104124

105125

106126
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
@@ -524,7 +544,12 @@ def test_parquet():
524544
with ensure_clean() as path:
525545
check(assert_type(DF.to_parquet(path), None), type(None))
526546
check(assert_type(DF.to_parquet(), bytes), bytes)
527-
check(assert_type(read_parquet(path), DataFrame), DataFrame)
547+
with pytest_warns_bounded(
548+
DeprecationWarning,
549+
"Passing a BlockManager to DataFrame is deprecated",
550+
lower="2.1.99",
551+
):
552+
check(assert_type(read_parquet(path), DataFrame), DataFrame)
528553

529554

530555
def test_parquet_options():
@@ -533,18 +558,33 @@ def test_parquet_options():
533558
assert_type(DF.to_parquet(path, compression=None, index=True), None),
534559
type(None),
535560
)
536-
check(assert_type(read_parquet(path), DataFrame), DataFrame)
561+
with pytest_warns_bounded(
562+
DeprecationWarning,
563+
"Passing a BlockManager to DataFrame is deprecated",
564+
lower="2.1.99",
565+
):
566+
check(assert_type(read_parquet(path), DataFrame), DataFrame)
537567

538568

539569
def test_feather():
540570
with ensure_clean() as path:
541571
check(assert_type(DF.to_feather(path), None), type(None))
542-
check(assert_type(read_feather(path), DataFrame), DataFrame)
543-
check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame)
572+
with pytest_warns_bounded(
573+
DeprecationWarning,
574+
"Passing a BlockManager to DataFrame is deprecated",
575+
lower="2.1.99",
576+
):
577+
check(assert_type(read_feather(path), DataFrame), DataFrame)
578+
check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame)
544579
with io.BytesIO() as bio:
545580
check(assert_type(DF.to_feather(bio), None), type(None))
546581
bio.seek(0)
547-
check(assert_type(read_feather(bio), DataFrame), DataFrame)
582+
with pytest_warns_bounded(
583+
DeprecationWarning,
584+
"Passing a BlockManager to DataFrame is deprecated",
585+
lower="2.1.99",
586+
):
587+
check(assert_type(read_feather(bio), DataFrame), DataFrame)
548588

549589

550590
def test_read_csv():
@@ -1394,25 +1434,42 @@ def test_all_read_without_lxml_dtype_backend() -> None:
13941434

13951435
if not WINDOWS:
13961436
check(assert_type(DF.to_orc(path), None), type(None))
1437+
with pytest_warns_bounded(
1438+
DeprecationWarning,
1439+
"Passing a BlockManager to DataFrame is deprecated",
1440+
lower="2.1.99",
1441+
):
1442+
check(
1443+
assert_type(
1444+
read_orc(path, dtype_backend="numpy_nullable"), DataFrame
1445+
),
1446+
DataFrame,
1447+
)
1448+
check(assert_type(DF.to_feather(path), None), type(None))
1449+
with pytest_warns_bounded(
1450+
DeprecationWarning,
1451+
"Passing a BlockManager to DataFrame is deprecated",
1452+
lower="2.1.99",
1453+
):
13971454
check(
1398-
assert_type(read_orc(path, dtype_backend="numpy_nullable"), DataFrame),
1455+
assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame),
13991456
DataFrame,
14001457
)
1401-
check(assert_type(DF.to_feather(path), None), type(None))
1402-
check(
1403-
assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame),
1404-
DataFrame,
1405-
)
14061458

1407-
check(
1408-
assert_type(
1409-
pd.to_numeric(
1410-
[1.0, 2.0, "blerg"], errors="ignore", dtype_backend="numpy_nullable"
1459+
with pytest_warns_bounded(
1460+
FutureWarning, "errors='ignore' is deprecated", lower="2.1.99"
1461+
):
1462+
check(
1463+
assert_type(
1464+
pd.to_numeric(
1465+
[1.0, 2.0, "blerg"],
1466+
errors="ignore",
1467+
dtype_backend="numpy_nullable",
1468+
),
1469+
npt.NDArray,
14111470
),
1412-
npt.NDArray,
1413-
),
1414-
np.ndarray,
1415-
)
1471+
np.ndarray,
1472+
)
14161473

14171474
with ensure_clean(".xlsx") as path:
14181475
as_str: str = path

0 commit comments

Comments
 (0)