Skip to content

fix pyright and pytest --nightly #819

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

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ ci:
autofix_prs: false
repos:
- repo: https://github.com/python/black
rev: 23.10.0
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.6
hooks:
- id: ruff
args: [
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class MultiIndex(Index[Any]):
def equals(self, other) -> bool: ...
def equal_levels(self, other): ...
def union(self, other, sort=...): ...
def intersection(self, other, sort: bool = ...): ...
def intersection(self, other: list | Self, sort: bool = ...): ...
def difference(self, other, sort=...): ...
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Self: ...
def insert(self, loc, item): ...
Expand Down
3 changes: 0 additions & 3 deletions scripts/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ def pytest(nightly: bool) -> None:
setup_steps = []
pytest_step = _step.pytest
if nightly:
pytest_step = dataclasses.replace(
_step.pytest, run=partial(_step.pytest.run, flags=())
)
setup_steps = [_step.nightly]
run_job(setup_steps + [pytest_step])

Expand Down
21 changes: 12 additions & 9 deletions tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,18 @@ def test_is_integer_dtype() -> None:


def test_is_interval() -> None:
check(assert_type(api.is_interval(obj), bool), bool)
check(assert_type(api.is_interval(nparr), bool), bool)
check(assert_type(api.is_interval(dtylike), bool), bool)
check(assert_type(api.is_interval(arr), bool), bool)
check(
assert_type(api.is_interval(dframe), bool),
bool,
)
check(assert_type(api.is_interval(ind), bool), bool)
with pytest_warns_bounded(
FutureWarning, "is_interval is deprecated", lower="2.1.99"
):
check(assert_type(api.is_interval(obj), bool), bool)
check(assert_type(api.is_interval(nparr), bool), bool)
check(assert_type(api.is_interval(dtylike), bool), bool)
check(assert_type(api.is_interval(arr), bool), bool)
check(
assert_type(api.is_interval(dframe), bool),
bool,
)
check(assert_type(api.is_interval(ind), bool), bool)


def test_is_interval_dtype() -> None:
Expand Down
47 changes: 28 additions & 19 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,8 @@ 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(UserWarning, "'M' will be deprecated", lower="2.1.99"):
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
df.resample("M", on="date")
# origin and offset params added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
df.resample("20min", origin="epoch", offset=pd.Timedelta(2, "minutes"), on="date")


Expand Down Expand Up @@ -1352,7 +1351,7 @@ def test_pipe() -> None:
def foo(df: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame(df)

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

# https://github.com/microsoft/pylance-release/issues/2133
dr = pd.date_range(start="2021-12-01", periods=24, freq="H")
with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"):
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 @@ -1906,18 +1906,24 @@ def test_frame_stack() -> None:
[[1.0, 2.0], [3.0, 4.0]], index=["cat", "dog"], columns=multicol2
)

check(
assert_type(
df_multi_level_cols2.stack(0), Union[pd.DataFrame, "pd.Series[Any]"]
),
pd.DataFrame,
)
check(
assert_type(
df_multi_level_cols2.stack([0, 1]), Union[pd.DataFrame, "pd.Series[Any]"]
),
pd.Series,
)
with pytest_warns_bounded(
FutureWarning,
"The previous implementation of stack is deprecated",
lower="2.1.99",
):
check(
assert_type(
df_multi_level_cols2.stack(0), Union[pd.DataFrame, "pd.Series[Any]"]
),
pd.DataFrame,
)
check(
assert_type(
df_multi_level_cols2.stack([0, 1]),
Union[pd.DataFrame, "pd.Series[Any]"],
),
pd.Series,
)


def test_frame_reindex() -> None:
Expand Down Expand Up @@ -2491,7 +2497,7 @@ 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(UserWarning, "'M' will be deprecated", lower="2.1.99"):
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
resampler = frame.resample("M", group_keys=True)
assert_type(resampler, "Resampler[pd.DataFrame]")

Expand Down Expand Up @@ -2858,8 +2864,11 @@ def test_interpolate_inplace() -> None:
def test_groupby_fillna_inplace() -> None:
# GH 691
groupby = pd.DataFrame({"a": range(3), "b": range(3)}).groupby("a")
check(assert_type(groupby.fillna(0), pd.DataFrame), pd.DataFrame)
check(assert_type(groupby.fillna(0, inplace=False), pd.DataFrame), pd.DataFrame)
with pytest_warns_bounded(
FutureWarning, "DataFrameGroupBy.fillna is deprecated", lower="2.1.99"
):
check(assert_type(groupby.fillna(0), pd.DataFrame), pd.DataFrame)
check(assert_type(groupby.fillna(0, inplace=False), pd.DataFrame), pd.DataFrame)
if TYPE_CHECKING_INVALID_USAGE:
groupby.fillna(0, inplace=True) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]

Expand Down
12 changes: 7 additions & 5 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_interval_range():
pd.IntervalIndex,
pd.Interval,
)
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"):
check(
assert_type(
pd.interval_range(
Expand Down Expand Up @@ -570,8 +570,9 @@ def test_interval_index_arrays():
pd.IntervalIndex,
pd.Interval,
)
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"):
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"))
check(
assert_type(
pd.IntervalIndex.from_arrays(left_s_ts, right_s_ts),
Expand Down Expand Up @@ -968,8 +969,9 @@ def test_index_constructors():

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


def test_intersection() -> None:
Expand Down
103 changes: 80 additions & 23 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,25 @@
def test_orc():
with ensure_clean() as path:
check(assert_type(DF.to_orc(path), None), type(None))
check(assert_type(read_orc(path), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_orc(path), DataFrame), DataFrame)


@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc_path():
with ensure_clean() as path:
pathlib_path = Path(path)
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)


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

with open(path, "rb") as file_r:
check(assert_type(read_orc(file_r), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_orc(file_r), DataFrame), DataFrame)


@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc_columns():
with ensure_clean() as path:
check(assert_type(DF.to_orc(path, index=False), None), type(None))
check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame)


@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
Expand Down Expand Up @@ -524,7 +544,12 @@ def test_parquet():
with ensure_clean() as path:
check(assert_type(DF.to_parquet(path), None), type(None))
check(assert_type(DF.to_parquet(), bytes), bytes)
check(assert_type(read_parquet(path), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_parquet(path), DataFrame), DataFrame)


def test_parquet_options():
Expand All @@ -533,18 +558,33 @@ def test_parquet_options():
assert_type(DF.to_parquet(path, compression=None, index=True), None),
type(None),
)
check(assert_type(read_parquet(path), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_parquet(path), DataFrame), DataFrame)


def test_feather():
with ensure_clean() as path:
check(assert_type(DF.to_feather(path), None), type(None))
check(assert_type(read_feather(path), DataFrame), DataFrame)
check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_feather(path), DataFrame), DataFrame)
check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame)
with io.BytesIO() as bio:
check(assert_type(DF.to_feather(bio), None), type(None))
bio.seek(0)
check(assert_type(read_feather(bio), DataFrame), DataFrame)
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(assert_type(read_feather(bio), DataFrame), DataFrame)


def test_read_csv():
Expand Down Expand Up @@ -1394,25 +1434,42 @@ def test_all_read_without_lxml_dtype_backend() -> None:

if not WINDOWS:
check(assert_type(DF.to_orc(path), None), type(None))
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(
assert_type(
read_orc(path, dtype_backend="numpy_nullable"), DataFrame
),
DataFrame,
)
check(assert_type(DF.to_feather(path), None), type(None))
with pytest_warns_bounded(
DeprecationWarning,
"Passing a BlockManager to DataFrame is deprecated",
lower="2.1.99",
):
check(
assert_type(read_orc(path, dtype_backend="numpy_nullable"), DataFrame),
assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame),
DataFrame,
)
check(assert_type(DF.to_feather(path), None), type(None))
check(
assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame),
DataFrame,
)

check(
assert_type(
pd.to_numeric(
[1.0, 2.0, "blerg"], errors="ignore", dtype_backend="numpy_nullable"
with pytest_warns_bounded(
FutureWarning, "errors='ignore' is deprecated", lower="2.1.99"
):
check(
assert_type(
pd.to_numeric(
[1.0, 2.0, "blerg"],
errors="ignore",
dtype_backend="numpy_nullable",
),
npt.NDArray,
),
npt.NDArray,
),
np.ndarray,
)
np.ndarray,
)

with ensure_clean(".xlsx") as path:
as_str: str = path
Expand Down
Loading