From a7aa063eab124c003c043fe6613b81112239fabd Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 15 Feb 2020 18:34:58 +0000 Subject: [PATCH 1/3] CI: silence numpy-dev failures (#32025) --- pandas/__init__.py | 1 + pandas/tests/api/test_api.py | 1 + pandas/tests/frame/test_cumulative.py | 9 +++++- pandas/tests/groupby/test_function.py | 4 +++ pandas/tests/groupby/test_transform.py | 29 +++++++++++++++++++ .../tests/scalar/timedelta/test_arithmetic.py | 17 +++++++++-- pandas/tests/series/test_cumulative.py | 7 +++++ 7 files changed, 65 insertions(+), 3 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 491bcb21f245d..6eda468eed23a 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -25,6 +25,7 @@ _np_version_under1p16, _np_version_under1p17, _np_version_under1p18, + _is_numpy_dev, ) try: diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 406d5f055797d..5aab5b814bae7 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -198,6 +198,7 @@ class TestPDApi(Base): "_np_version_under1p16", "_np_version_under1p17", "_np_version_under1p18", + "_is_numpy_dev", "_testing", "_tslib", "_typing", diff --git a/pandas/tests/frame/test_cumulative.py b/pandas/tests/frame/test_cumulative.py index b545d6aa8afd3..2466547e2948b 100644 --- a/pandas/tests/frame/test_cumulative.py +++ b/pandas/tests/frame/test_cumulative.py @@ -7,8 +7,9 @@ """ import numpy as np +import pytest -from pandas import DataFrame, Series +from pandas import DataFrame, Series, _is_numpy_dev import pandas._testing as tm @@ -73,6 +74,9 @@ def test_cumprod(self, datetime_frame): df.cumprod(0) df.cumprod(1) + @pytest.mark.xfail( + _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + ) def test_cummin(self, datetime_frame): datetime_frame.loc[5:10, 0] = np.nan datetime_frame.loc[10:15, 1] = np.nan @@ -96,6 +100,9 @@ def test_cummin(self, datetime_frame): cummin_xs = datetime_frame.cummin(axis=1) assert np.shape(cummin_xs) == np.shape(datetime_frame) + @pytest.mark.xfail( + _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + ) def test_cummax(self, datetime_frame): datetime_frame.loc[5:10, 0] = np.nan datetime_frame.loc[10:15, 1] = np.nan diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 97cf1af1d2e9e..a9a5d2b3c9823 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -17,6 +17,7 @@ NaT, Series, Timestamp, + _is_numpy_dev, date_range, isna, ) @@ -685,6 +686,9 @@ def test_numpy_compat(func): getattr(g, func)(foo=1) +@pytest.mark.xfail( + _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" +) def test_cummin_cummax(): # GH 15048 num_types = [np.int32, np.int64, np.float32, np.float64] diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index 6c05c4038a829..b3183de9f7787 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -15,6 +15,7 @@ MultiIndex, Series, Timestamp, + _is_numpy_dev, concat, date_range, ) @@ -317,6 +318,34 @@ def test_dispatch_transform(tsframe): tm.assert_frame_equal(filled, expected) +def test_transform_transformation_func(transformation_func): + # GH 30918 + df = DataFrame( + { + "A": ["foo", "foo", "foo", "foo", "bar", "bar", "baz"], + "B": [1, 2, np.nan, 3, 3, np.nan, 4], + } + ) + + if transformation_func in ["pad", "backfill", "tshift", "corrwith", "cumcount"]: + # These transformation functions are not yet covered in this test + pytest.xfail("See GH 31269 and GH 31270") + elif _is_numpy_dev and transformation_func in ["cummin"]: + pytest.xfail("https://github.com/pandas-dev/pandas/issues/31992") + elif transformation_func == "fillna": + test_op = lambda x: x.transform("fillna", value=0) + mock_op = lambda x: x.fillna(value=0) + else: + test_op = lambda x: x.transform(transformation_func) + mock_op = lambda x: getattr(x, transformation_func)() + + result = test_op(df.groupby("A")) + groups = [df[["B"]].iloc[:4], df[["B"]].iloc[4:6], df[["B"]].iloc[6:]] + expected = concat([mock_op(g) for g in groups]) + + tm.assert_frame_equal(result, expected) + + def test_transform_select_columns(df): f = lambda x: x.mean() result = df.groupby("A")[["C", "D"]].transform(f) diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 6a9ef86c11292..7b762ed020290 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -8,7 +8,7 @@ import pytest import pandas as pd -from pandas import NaT, Timedelta, Timestamp, offsets +from pandas import NaT, Timedelta, Timestamp, _is_numpy_dev, offsets import pandas._testing as tm from pandas.core import ops @@ -377,7 +377,20 @@ def test_td_div_numeric_scalar(self): assert isinstance(result, Timedelta) assert result == Timedelta(days=2) - @pytest.mark.parametrize("nan", [np.nan, np.float64("NaN"), float("nan")]) + @pytest.mark.parametrize( + "nan", + [ + np.nan, + pytest.param( + np.float64("NaN"), + marks=pytest.mark.xfail( + _is_numpy_dev, + reason="https://github.com/pandas-dev/pandas/issues/31992", + ), + ), + float("nan"), + ], + ) def test_td_div_nan(self, nan): # np.float64('NaN') has a 'dtype' attr, avoid treating as array td = Timedelta(10, unit="d") diff --git a/pandas/tests/series/test_cumulative.py b/pandas/tests/series/test_cumulative.py index 885b5bf0476f2..b0065992b850a 100644 --- a/pandas/tests/series/test_cumulative.py +++ b/pandas/tests/series/test_cumulative.py @@ -11,6 +11,7 @@ import pytest import pandas as pd +from pandas import _is_numpy_dev import pandas._testing as tm @@ -37,6 +38,9 @@ def test_cumsum(self, datetime_series): def test_cumprod(self, datetime_series): _check_accum_op("cumprod", datetime_series) + @pytest.mark.xfail( + _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + ) def test_cummin(self, datetime_series): tm.assert_numpy_array_equal( datetime_series.cummin().values, @@ -49,6 +53,9 @@ def test_cummin(self, datetime_series): tm.assert_series_equal(result, expected) + @pytest.mark.xfail( + _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + ) def test_cummax(self, datetime_series): tm.assert_numpy_array_equal( datetime_series.cummax().values, From c2be05162a758a68b477dbcf5fe55bdd69c8709d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 16 Feb 2020 17:43:56 +0000 Subject: [PATCH 2/3] CI: change np-dev xfails to not strict (#32031) --- pandas/tests/frame/test_cumulative.py | 8 ++++++-- pandas/tests/groupby/test_function.py | 4 +++- pandas/tests/scalar/timedelta/test_arithmetic.py | 1 + pandas/tests/series/test_cumulative.py | 8 ++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/test_cumulative.py b/pandas/tests/frame/test_cumulative.py index 2466547e2948b..486cbfb2761e0 100644 --- a/pandas/tests/frame/test_cumulative.py +++ b/pandas/tests/frame/test_cumulative.py @@ -75,7 +75,9 @@ def test_cumprod(self, datetime_frame): df.cumprod(1) @pytest.mark.xfail( - _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + _is_numpy_dev, + reason="https://github.com/pandas-dev/pandas/issues/31992", + strict=False, ) def test_cummin(self, datetime_frame): datetime_frame.loc[5:10, 0] = np.nan @@ -101,7 +103,9 @@ def test_cummin(self, datetime_frame): assert np.shape(cummin_xs) == np.shape(datetime_frame) @pytest.mark.xfail( - _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + _is_numpy_dev, + reason="https://github.com/pandas-dev/pandas/issues/31992", + strict=False, ) def test_cummax(self, datetime_frame): datetime_frame.loc[5:10, 0] = np.nan diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index a9a5d2b3c9823..087b1286151d7 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -687,7 +687,9 @@ def test_numpy_compat(func): @pytest.mark.xfail( - _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + _is_numpy_dev, + reason="https://github.com/pandas-dev/pandas/issues/31992", + strict=False, ) def test_cummin_cummax(): # GH 15048 diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 7b762ed020290..555b47c8dc0fc 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -386,6 +386,7 @@ def test_td_div_numeric_scalar(self): marks=pytest.mark.xfail( _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992", + strict=False, ), ), float("nan"), diff --git a/pandas/tests/series/test_cumulative.py b/pandas/tests/series/test_cumulative.py index b0065992b850a..0cb1c038478f5 100644 --- a/pandas/tests/series/test_cumulative.py +++ b/pandas/tests/series/test_cumulative.py @@ -39,7 +39,9 @@ def test_cumprod(self, datetime_series): _check_accum_op("cumprod", datetime_series) @pytest.mark.xfail( - _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + _is_numpy_dev, + reason="https://github.com/pandas-dev/pandas/issues/31992", + strict=False, ) def test_cummin(self, datetime_series): tm.assert_numpy_array_equal( @@ -54,7 +56,9 @@ def test_cummin(self, datetime_series): tm.assert_series_equal(result, expected) @pytest.mark.xfail( - _is_numpy_dev, reason="https://github.com/pandas-dev/pandas/issues/31992" + _is_numpy_dev, + reason="https://github.com/pandas-dev/pandas/issues/31992", + strict=False, ) def test_cummax(self, datetime_series): tm.assert_numpy_array_equal( From fe282189800c5c7921af8af59089648814767414 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 17 Feb 2020 13:17:41 +0000 Subject: [PATCH 3/3] test_transform_transformation_func not backported --- pandas/tests/groupby/test_transform.py | 29 -------------------------- 1 file changed, 29 deletions(-) diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index b3183de9f7787..6c05c4038a829 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -15,7 +15,6 @@ MultiIndex, Series, Timestamp, - _is_numpy_dev, concat, date_range, ) @@ -318,34 +317,6 @@ def test_dispatch_transform(tsframe): tm.assert_frame_equal(filled, expected) -def test_transform_transformation_func(transformation_func): - # GH 30918 - df = DataFrame( - { - "A": ["foo", "foo", "foo", "foo", "bar", "bar", "baz"], - "B": [1, 2, np.nan, 3, 3, np.nan, 4], - } - ) - - if transformation_func in ["pad", "backfill", "tshift", "corrwith", "cumcount"]: - # These transformation functions are not yet covered in this test - pytest.xfail("See GH 31269 and GH 31270") - elif _is_numpy_dev and transformation_func in ["cummin"]: - pytest.xfail("https://github.com/pandas-dev/pandas/issues/31992") - elif transformation_func == "fillna": - test_op = lambda x: x.transform("fillna", value=0) - mock_op = lambda x: x.fillna(value=0) - else: - test_op = lambda x: x.transform(transformation_func) - mock_op = lambda x: getattr(x, transformation_func)() - - result = test_op(df.groupby("A")) - groups = [df[["B"]].iloc[:4], df[["B"]].iloc[4:6], df[["B"]].iloc[6:]] - expected = concat([mock_op(g) for g in groups]) - - tm.assert_frame_equal(result, expected) - - def test_transform_select_columns(df): f = lambda x: x.mean() result = df.groupby("A")[["C", "D"]].transform(f)