Skip to content

Commit f1bab3e

Browse files
authored
MAINT: Fix nightly by skipping and noting problematic code (#301)
* MAINT: Fix nightly * MAINT: Add skips for problematic tests on nightly Catch warnings after 1.5.0 is out * CLN: Refactor to simplify
1 parent 8afdc56 commit f1bab3e

File tree

7 files changed

+39
-15
lines changed

7 files changed

+39
-15
lines changed

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
Final,
66
)
77

8+
from packaging.version import parse
9+
import pandas as pd
10+
811
from pandas._typing import T
912

1013
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
14+
PD_LT_15 = parse(pd.__version__) < parse("1.5.0")
1115

1216

1317
def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left") -> T:

tests/test_errors.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
from typing import TYPE_CHECKING
44
import warnings
55

6-
from packaging.version import parse
7-
import pandas as pd
86
from pandas import errors
97
import pytest
108

11-
PD_LT_15 = parse(pd.__version__) < parse("1.5.0")
9+
from tests import PD_LT_15
1210

1311
if TYPE_CHECKING or PD_LT_15:
1412
# TODO: Remove all imports below after switch to 1.5.x, these moved to pandas.errors

tests/test_frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,10 @@ def sample_to_df(x: pd.DataFrame) -> pd.DataFrame:
16251625
return x.sample()
16261626

16271627
check(
1628-
assert_type(df.groupby("col1").apply(sample_to_df), pd.DataFrame), pd.DataFrame
1628+
assert_type(
1629+
df.groupby("col1", group_keys=False).apply(sample_to_df), pd.DataFrame
1630+
),
1631+
pd.DataFrame,
16291632
)
16301633

16311634

tests/test_io.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
)
1515

1616
import numpy as np
17-
from packaging.version import parse
1817
import pandas as pd
1918
from pandas import (
2019
DataFrame,
2120
HDFStore,
2221
Series,
23-
__version__,
2422
read_clipboard,
2523
read_csv,
2624
read_excel,
@@ -46,7 +44,10 @@
4644
import sqlalchemy
4745
from typing_extensions import assert_type
4846

49-
from tests import check
47+
from tests import (
48+
PD_LT_15,
49+
check,
50+
)
5051

5152
from pandas.io.api import to_pickle
5253
from pandas.io.clipboard import PyperclipException
@@ -64,8 +65,6 @@
6465
DF = DataFrame({"a": [1, 2, 3], "b": [0.0, 0.0, 0.0]})
6566
CWD = os.path.split(os.path.abspath(__file__))[0]
6667

67-
PD_LT_15 = parse(__version__) < parse("1.5.0")
68-
6968

7069
@pytest.mark.skipif(PD_LT_15, reason="pandas 1.5.0 or later required")
7170
def test_orc():
@@ -188,6 +187,8 @@ def test_read_stata_df():
188187
check(assert_type(read_stata(path), pd.DataFrame), pd.DataFrame)
189188

190189

190+
# Remove test when pandas 1.5.0 is released
191+
@pytest.mark.skipif(not PD_LT_15, reason="Keyword only in 1.5.0")
191192
def test_read_stata_iterator_positional():
192193
with ensure_clean() as path:
193194
str_path = str(path)
@@ -657,7 +658,9 @@ def test_excel_writer():
657658
with pd.ExcelWriter(path) as ew:
658659
check(assert_type(ew, pd.ExcelWriter), pd.ExcelWriter)
659660
DF.to_excel(ew, sheet_name="A")
660-
check(assert_type(ew.handles, IOHandles[bytes]), IOHandles)
661+
if PD_LT_15:
662+
# Remove after 1.5 and remove handles from ExcelWriter
663+
check(assert_type(ew.handles, IOHandles[bytes]), IOHandles)
661664
check(assert_type(read_excel(path, sheet_name="A"), DataFrame), DataFrame)
662665
check(assert_type(read_excel(path), DataFrame), DataFrame)
663666
ef = pd.ExcelFile(path)

tests/test_plotting.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ def test_plot_keywords(close_figures):
536536
colormap="jet",
537537
table=True,
538538
stacked=True,
539-
sort_columns=True,
540539
secondary_y=True,
541540
mark_right=True,
542541
include_bool=True,

tests/test_resampler.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
)
1717
from pandas.core.groupby.generic import SeriesGroupBy
1818
from pandas.core.resample import Resampler
19+
import pytest
1920
from typing_extensions import assert_type
2021

2122
from pandas._typing import Scalar
2223

23-
from tests import check
24+
from tests import (
25+
PD_LT_15,
26+
check,
27+
)
2428

2529
DR = date_range("1999-1-1", periods=365, freq="D")
2630
DF_ = DataFrame(np.random.standard_normal((365, 1)), index=DR)
@@ -297,7 +301,11 @@ def s2scalar(val: Series) -> float:
297301

298302
check(S.resample("m").aggregate(np.sum), Series)
299303
check(S.resample("m").aggregate("sum"), Series)
300-
check(S.resample("m").aggregate(s2series), Series)
304+
if PD_LT_15:
305+
check(S.resample("m").aggregate(s2series), Series)
306+
else:
307+
with pytest.warns(FutureWarning, match="Not prepending group keys"):
308+
check(S.resample("m").aggregate(s2series), Series)
301309
check(S.resample("m").aggregate(s2scalar), Series)
302310
check(S.resample("m").aggregate([np.mean]), DataFrame)
303311
check(S.resample("m").aggregate(["sum", np.mean]), DataFrame)
@@ -317,7 +325,11 @@ def df2scalar(val: DataFrame) -> float:
317325

318326
check(DF.resample("m").aggregate(np.sum), DataFrame)
319327
check(DF.resample("m").aggregate("sum"), DataFrame)
320-
check(DF.resample("m").aggregate(df2frame), DataFrame)
328+
if PD_LT_15:
329+
check(DF.resample("m").aggregate(df2frame), DataFrame)
330+
else:
331+
with pytest.warns(FutureWarning, match="Not prepending group keys"):
332+
check(DF.resample("m").aggregate(df2frame), DataFrame)
321333
check(DF.resample("m").aggregate(df2series), DataFrame)
322334
check(DF.resample("m").aggregate(df2scalar), DataFrame)
323335
check(DF.resample("m").aggregate([np.mean]), DataFrame)

tests/test_series.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
)
3535

3636
from tests import (
37+
PD_LT_15,
3738
TYPE_CHECKING_INVALID_USAGE,
3839
check,
3940
)
@@ -259,7 +260,11 @@ def test_types_rank() -> None:
259260
s.rank(method="min", pct=True)
260261
with pytest.warns(FutureWarning, match="Dropping of nuisance columns"):
261262
s.rank(method="dense", ascending=True)
262-
s.rank(method="first", numeric_only=True)
263+
if PD_LT_15:
264+
s.rank(method="first", numeric_only=True)
265+
else:
266+
with pytest.warns(FutureWarning, match="Calling Series.rank with numeric_only"):
267+
s.rank(method="first", numeric_only=True)
263268

264269

265270
def test_types_mean() -> None:

0 commit comments

Comments
 (0)