Skip to content

CI: ignore warnings from pandas-nightly #669

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 2 commits into from
May 1, 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
10 changes: 8 additions & 2 deletions scripts/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ def stubtest(allowlist: str, check_missing: bool, nightly: bool) -> None:


def pytest(nightly: bool) -> None:
steps = [_step.nightly] if nightly else []
run_job(steps + [_step.pytest])
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])


def mypy_src(mypy_nightly: bool) -> None:
Expand Down
6 changes: 4 additions & 2 deletions scripts/test/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from pathlib import Path
import subprocess
import sys
Expand All @@ -13,8 +15,8 @@ def pyright_src():
subprocess.run(cmd, check=True)


def pytest():
cmd = ["pytest", "--cache-clear", "-Werror"]
def pytest(flags: tuple[str, ...] = ("-Werror",)):
cmd = ["pytest", "--cache-clear", *flags]
subprocess.run(cmd, check=True)


Expand Down
118 changes: 35 additions & 83 deletions tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

from pandas._typing import DtypeObj

from tests import (
check,
pytest_warns_bounded,
)
from tests import check

nparr = np.array([1, 2, 3])
arr = pd.Series([1, 2, 3])
Expand Down Expand Up @@ -55,20 +52,12 @@ def test_is_bool_dtype() -> None:


def test_is_categorical_dtype() -> None:
with pytest_warns_bounded(
FutureWarning,
match="is_categorical_dtype is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_categorical_dtype(arr), bool), bool)
check(assert_type(api.is_categorical_dtype(nparr), bool), bool)
check(assert_type(api.is_categorical_dtype(dtylike), bool), bool)
check(
assert_type(api.is_categorical_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_categorical_dtype(ind), bool), bool)
check(assert_type(api.is_categorical_dtype(ExtensionDtype), bool), bool)
check(assert_type(api.is_categorical_dtype(arr), bool), bool)
check(assert_type(api.is_categorical_dtype(nparr), bool), bool)
check(assert_type(api.is_categorical_dtype(dtylike), bool), bool)
check(assert_type(api.is_categorical_dtype(dframe), bool), bool)
check(assert_type(api.is_categorical_dtype(ind), bool), bool)
check(assert_type(api.is_categorical_dtype(ExtensionDtype), bool), bool)


def test_is_complex() -> None:
Expand Down Expand Up @@ -132,20 +121,12 @@ def test_is_datetime64_ns_dtype() -> None:


def test_is_datetime64tz_dtype() -> None:
with pytest_warns_bounded(
FutureWarning,
match="is_datetime64tz_dtype is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_datetime64tz_dtype(arr), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(nparr), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(dtylike), bool), bool)
check(
assert_type(api.is_datetime64tz_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_datetime64tz_dtype(ind), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(ExtensionDtype), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(arr), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(nparr), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(dtylike), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(dframe), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(ind), bool), bool)
check(assert_type(api.is_datetime64tz_dtype(ExtensionDtype), bool), bool)


def test_is_dict_like() -> None:
Expand Down Expand Up @@ -222,20 +203,12 @@ def test_is_hashable() -> None:


def test_is_int64_dtype() -> None:
with pytest_warns_bounded(
FutureWarning,
match="is_int64_dtype is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_int64_dtype(arr), bool), bool)
check(assert_type(api.is_int64_dtype(nparr), bool), bool)
check(assert_type(api.is_int64_dtype(dtylike), bool), bool)
check(
assert_type(api.is_int64_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_int64_dtype(ind), bool), bool)
# check(assert_type(api.is_int64_dtype(ExtensionDtype), bool), bool) pandas GH 50923
check(assert_type(api.is_int64_dtype(arr), bool), bool)
check(assert_type(api.is_int64_dtype(nparr), bool), bool)
check(assert_type(api.is_int64_dtype(dtylike), bool), bool)
check(assert_type(api.is_int64_dtype(dframe), bool), bool)
check(assert_type(api.is_int64_dtype(ind), bool), bool)
# check(assert_type(api.is_int64_dtype(ExtensionDtype), bool), bool) pandas GH 50923


def test_is_integer() -> None:
Expand Down Expand Up @@ -275,21 +248,13 @@ def test_is_interval() -> None:


def test_is_interval_dtype() -> None:
with pytest_warns_bounded(
FutureWarning,
match="is_interval_dtype is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_interval_dtype(obj), bool), bool)
check(assert_type(api.is_interval_dtype(nparr), bool), bool)
check(assert_type(api.is_interval_dtype(dtylike), bool), bool)
check(assert_type(api.is_interval_dtype(arr), bool), bool)
check(
assert_type(api.is_interval_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_interval_dtype(ind), bool), bool)
check(assert_type(api.is_interval_dtype(ExtensionDtype), bool), bool)
check(assert_type(api.is_interval_dtype(obj), bool), bool)
check(assert_type(api.is_interval_dtype(nparr), bool), bool)
check(assert_type(api.is_interval_dtype(dtylike), bool), bool)
check(assert_type(api.is_interval_dtype(arr), bool), bool)
check(assert_type(api.is_interval_dtype(dframe), bool), bool)
check(assert_type(api.is_interval_dtype(ind), bool), bool)
check(assert_type(api.is_interval_dtype(ExtensionDtype), bool), bool)


def test_is_iterator() -> None:
Expand Down Expand Up @@ -362,20 +327,12 @@ def test_is_object_dtype() -> None:


def test_is_period_dtype() -> None:
with pytest_warns_bounded(
FutureWarning,
match="is_period_dtype is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_period_dtype(arr), bool), bool)
check(assert_type(api.is_period_dtype(nparr), bool), bool)
check(assert_type(api.is_period_dtype(dtylike), bool), bool)
check(
assert_type(api.is_period_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_period_dtype(ind), bool), bool)
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)
check(assert_type(api.is_period_dtype(arr), bool), bool)
check(assert_type(api.is_period_dtype(nparr), bool), bool)
check(assert_type(api.is_period_dtype(dtylike), bool), bool)
check(assert_type(api.is_period_dtype(dframe), bool), bool)
check(assert_type(api.is_period_dtype(ind), bool), bool)
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)


def test_is_re() -> None:
Expand Down Expand Up @@ -421,14 +378,9 @@ def test_is_signed_integer_dtype() -> None:


def test_is_sparse() -> None:
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_sparse(arr), bool), bool)
check(assert_type(api.is_sparse(nparr), bool), bool)
check(assert_type(api.is_sparse(dframe), bool), bool)
check(assert_type(api.is_sparse(arr), bool), bool)
check(assert_type(api.is_sparse(nparr), bool), bool)
check(assert_type(api.is_sparse(dframe), bool), bool)


def test_is_string_dtype() -> None:
Expand Down
127 changes: 46 additions & 81 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
PD_LTE_20,
TYPE_CHECKING_INVALID_USAGE,
check,
pytest_warns_bounded,
)

from pandas.io.formats.style import Styler
Expand Down Expand Up @@ -727,17 +726,12 @@ def gethead(s: pd.Series, y: int) -> pd.Series:

def test_types_applymap() -> None:
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
with pytest_warns_bounded(
FutureWarning,
match="DataFrame.applymap has been deprecated. Use DataFrame.map instead.",
lower="2.0.99",
):
df.applymap(lambda x: x**2)
df.applymap(np.exp)
df.applymap(str)
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
df.applymap(np.exp, na_action="ignore")
df.applymap(str, na_action=None)
df.applymap(lambda x: x**2)
df.applymap(np.exp)
df.applymap(str)
# na_action parameter was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
df.applymap(np.exp, na_action="ignore")
df.applymap(str, na_action=None)


def test_types_element_wise_arithmetic() -> None:
Expand Down Expand Up @@ -881,12 +875,7 @@ def test_types_groupby() -> None:
df4: pd.DataFrame = df.groupby(by=["col1", "col2"]).count()
df5: pd.DataFrame = df.groupby(by=["col1", "col2"]).filter(lambda x: x["col1"] > 0)
df6: pd.DataFrame = df.groupby(by=["col1", "col2"]).nunique()
with pytest_warns_bounded(
FutureWarning,
match="DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated",
lower="2.0.99",
):
df7: pd.DataFrame = df.groupby(by="col1").apply(sum)
df7: pd.DataFrame = df.groupby(by="col1").apply(sum)
df8: pd.DataFrame = df.groupby("col1").transform("sum")
s1: pd.Series = df.set_index("col1")["col2"]
s2: pd.Series = s1.groupby("col1").transform("sum")
Expand Down Expand Up @@ -1098,22 +1087,17 @@ def test_to_markdown() -> None:
def test_types_to_feather() -> None:
pytest.importorskip("pyarrow")
df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]})
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
with ensure_clean() as path:
df.to_feather(path)
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)

# to_feather has been able to accept a buffer since pandas 1.0.0
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
# Docstring and type were updated in 1.2.0.
# https://github.com/pandas-dev/pandas/pull/35408
with open(path, mode="wb") as file:
df.to_feather(file)
with ensure_clean() as path:
df.to_feather(path)
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)

# to_feather has been able to accept a buffer since pandas 1.0.0
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
# Docstring and type were updated in 1.2.0.
# https://github.com/pandas-dev/pandas/pull/35408
with open(path, mode="wb") as file:
df.to_feather(file)


# compare() method added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
Expand Down Expand Up @@ -1344,12 +1328,7 @@ def test_types_to_parquet() -> None:
allows_duplicate_labels=False
)
with ensure_clean() as path:
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
df.to_parquet(Path(path))
df.to_parquet(Path(path))
# to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
b: bytes = df.to_parquet()

Expand Down Expand Up @@ -1475,19 +1454,14 @@ def test_types_regressions() -> None:

# https://github.com/microsoft/python-type-stubs/issues/115
df = pd.DataFrame({"A": [1, 2, 3], "B": [5, 6, 7]})
with pytest_warns_bounded(
FutureWarning,
match="The 'closed' keyword in DatetimeIndex construction is deprecated",
lower="2.0.99",
):
pd.DatetimeIndex(
data=df["A"],
tz=None,
normalize=False,
closed=None,
ambiguous="NaT",
copy=True,
)
pd.DatetimeIndex(
data=df["A"],
tz=None,
normalize=False,
closed=None,
ambiguous="NaT",
copy=True,
)


def test_read_csv() -> None:
Expand Down Expand Up @@ -2053,41 +2027,32 @@ def test_groupby_apply() -> None:
def sum_mean(x: pd.DataFrame) -> float:
return x.sum().mean()

with pytest_warns_bounded(
FutureWarning,
match="DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated",
lower="2.0.99",
):
check(assert_type(df.groupby("col1").apply(sum_mean), pd.Series), pd.Series)
check(assert_type(df.groupby("col1").apply(sum_mean), pd.Series), pd.Series)

lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()
check(
assert_type(df.groupby("col1").apply(lfunc), pd.Series),
pd.Series,
)
lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()
check(assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series)

def sum_to_list(x: pd.DataFrame) -> list:
return x.sum().tolist()
def sum_to_list(x: pd.DataFrame) -> list:
return x.sum().tolist()

check(assert_type(df.groupby("col1").apply(sum_to_list), pd.Series), pd.Series)
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()
def sum_to_series(x: pd.DataFrame) -> pd.Series:
return x.sum()

check(
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame),
pd.DataFrame,
)
check(
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame), pd.DataFrame
)

def sample_to_df(x: pd.DataFrame) -> pd.DataFrame:
return x.sample()
def sample_to_df(x: pd.DataFrame) -> pd.DataFrame:
return x.sample()

check(
assert_type(
df.groupby("col1", group_keys=False).apply(sample_to_df), pd.DataFrame
),
pd.DataFrame,
)
check(
assert_type(
df.groupby("col1", group_keys=False).apply(sample_to_df), pd.DataFrame
),
pd.DataFrame,
)


def test_resample() -> None:
Expand Down
Loading