From c26b20040cb30d288812430a6326262b8af8cb98 Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 2 Dec 2018 21:32:01 +0800 Subject: [PATCH 1/5] Add test for rdivmod on EA array (GH23287) --- pandas/tests/extension/base/ops.py | 11 ++++++++++- pandas/tests/extension/decimal/test_decimal.py | 5 +++++ pandas/tests/extension/json/test_json.py | 3 +++ pandas/tests/extension/test_categorical.py | 3 +++ pandas/tests/extension/test_integer.py | 5 +++++ pandas/tests/extension/test_period.py | 3 +++ pandas/tests/extension/test_sparse.py | 5 +++++ 7 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index cd5e55d9871b2..d5d46a58c134f 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -1,6 +1,7 @@ import operator import pytest +import numpy as np import pandas as pd from pandas.core import ops @@ -91,10 +92,18 @@ def test_divmod(self, data): self._check_divmod_op(s, divmod, 1, exc=self.divmod_exc) self._check_divmod_op(1, ops.rdivmod, s, exc=self.divmod_exc) - def test_divmod_series_array(self, data): + def test_divmod_series_array(self, data, ones): + #pytest.set_trace() s = pd.Series(data) self._check_divmod_op(s, divmod, data) + #pytest.set_trace() + other = ones * 2 + self._check_divmod_op(other, ops.rdivmod, s) + + other = pd.Series(other) + self._check_divmod_op(other, ops.rdivmod, s) + def test_add_series_with_extension_array(self, data): s = pd.Series(data) result = s + data diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 6281c5360cd03..80829dc5043c9 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -23,6 +23,11 @@ def data(): return DecimalArray(make_data()) +@pytest.fixture +def ones(): + return DecimalArray([decimal.Decimal(1) for _ in range(100)]) + + @pytest.fixture def data_missing(): return DecimalArray([decimal.Decimal('NaN'), decimal.Decimal(1)]) diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index 9ee131950f19c..f91b8ecd2b38e 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -290,6 +290,9 @@ def test_add_series_with_extension_array(self, data): with pytest.raises(TypeError, match="unsupported"): ser + data + def test_divmod_series_array(self): + pass + def _check_divmod_op(self, s, op, other, exc=NotImplementedError): return super(TestArithmeticOps, self)._check_divmod_op( s, op, other, exc=TypeError diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index ac52d8f15b8ce..335537269df4a 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -214,6 +214,9 @@ def test_add_series_with_extension_array(self, data): with pytest.raises(TypeError, match="cannot perform"): ser + data + def test_divmod_series_array(self): + pass + def _check_divmod_op(self, s, op, other, exc=NotImplementedError): return super(TestArithmeticOps, self)._check_divmod_op( s, op, other, exc=TypeError diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index aadf9f2f12b68..0ca1e77093230 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -42,6 +42,11 @@ def data(dtype): return integer_array(make_data(), dtype=dtype) +@pytest.fixture +def ones(dtype): + return integer_array(np.ones(100), dtype=dtype) + + @pytest.fixture def data_missing(dtype): return integer_array([np.nan, 1], dtype=dtype) diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 813efcb5678d3..da2f1ba897819 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -125,6 +125,9 @@ def test_direct_arith_with_series_returns_not_implemented(self, data): result = data.__sub__(other) assert result is NotImplemented + def test_divmod_series_array(self): + pass + class TestCasting(BasePeriodTests, base.BaseCastingTests): pass diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index 146dea2b65d83..f60592254d434 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -34,6 +34,11 @@ def data(request): return res +@pytest.fixture +def ones(request): + return SparseArray(np.ones(100)) + + @pytest.fixture(params=[0, np.nan]) def data_missing(request): """Length 2 array with [NA, Valid]""" From a4c8665cb57fea7387bda305edc218947d46db1e Mon Sep 17 00:00:00 2001 From: makbigc Date: Thu, 27 Dec 2018 17:45:10 +0800 Subject: [PATCH 2/5] Rename ones as data_for_ones --- pandas/tests/extension/base/ops.py | 7 ++----- pandas/tests/extension/decimal/test_decimal.py | 2 +- pandas/tests/extension/test_integer.py | 2 +- pandas/tests/extension/test_period.py | 8 +++++--- pandas/tests/extension/test_sparse.py | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index d5d46a58c134f..7712a611bed4a 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -1,7 +1,6 @@ import operator import pytest -import numpy as np import pandas as pd from pandas.core import ops @@ -92,13 +91,11 @@ def test_divmod(self, data): self._check_divmod_op(s, divmod, 1, exc=self.divmod_exc) self._check_divmod_op(1, ops.rdivmod, s, exc=self.divmod_exc) - def test_divmod_series_array(self, data, ones): - #pytest.set_trace() + def test_divmod_series_array(self, data, data_for_ones): s = pd.Series(data) self._check_divmod_op(s, divmod, data) - #pytest.set_trace() - other = ones * 2 + other = data_for_ones * 2 self._check_divmod_op(other, ops.rdivmod, s) other = pd.Series(other) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 80829dc5043c9..93f6f5cbaa505 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -24,7 +24,7 @@ def data(): @pytest.fixture -def ones(): +def data_for_ones(): return DecimalArray([decimal.Decimal(1) for _ in range(100)]) diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 0ca1e77093230..cba242a912277 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -43,7 +43,7 @@ def data(dtype): @pytest.fixture -def ones(dtype): +def data_for_ones(dtype): return integer_array(np.ones(100), dtype=dtype) diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index da2f1ba897819..a0f359f34d476 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -20,6 +20,11 @@ def data(dtype): return PeriodArray(np.arange(1970, 2070), freq=dtype.freq) +@pytest.fixture +def data_for_ones(dtype): + return PeriodArray(np.ones(100), freq=dtype.freq) + + @pytest.fixture def data_for_sorting(dtype): return PeriodArray([2018, 2019, 2017], freq=dtype.freq) @@ -125,9 +130,6 @@ def test_direct_arith_with_series_returns_not_implemented(self, data): result = data.__sub__(other) assert result is NotImplemented - def test_divmod_series_array(self): - pass - class TestCasting(BasePeriodTests, base.BaseCastingTests): pass diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index f60592254d434..ce8b39d6c72c8 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -35,7 +35,7 @@ def data(request): @pytest.fixture -def ones(request): +def data_for_ones(request): return SparseArray(np.ones(100)) From 269661decb2363ec4893dcc19383ad04c352c43d Mon Sep 17 00:00:00 2001 From: makbigc Date: Thu, 27 Dec 2018 18:33:51 +0800 Subject: [PATCH 3/5] Change data_for_ones to data_for_twos --- pandas/tests/extension/base/ops.py | 4 ++-- pandas/tests/extension/decimal/test_decimal.py | 4 ++-- pandas/tests/extension/test_integer.py | 4 ++-- pandas/tests/extension/test_period.py | 4 ++-- pandas/tests/extension/test_sparse.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 7712a611bed4a..2ac68c52d53c7 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -91,11 +91,11 @@ def test_divmod(self, data): self._check_divmod_op(s, divmod, 1, exc=self.divmod_exc) self._check_divmod_op(1, ops.rdivmod, s, exc=self.divmod_exc) - def test_divmod_series_array(self, data, data_for_ones): + def test_divmod_series_array(self, data, data_for_twos): s = pd.Series(data) self._check_divmod_op(s, divmod, data) - other = data_for_ones * 2 + other = data_for_twos self._check_divmod_op(other, ops.rdivmod, s) other = pd.Series(other) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 93f6f5cbaa505..686bd898f5171 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -24,8 +24,8 @@ def data(): @pytest.fixture -def data_for_ones(): - return DecimalArray([decimal.Decimal(1) for _ in range(100)]) +def data_for_twos(): + return DecimalArray([decimal.Decimal(2) for _ in range(100)]) @pytest.fixture diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index cba242a912277..a8dcabbb824d5 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -43,8 +43,8 @@ def data(dtype): @pytest.fixture -def data_for_ones(dtype): - return integer_array(np.ones(100), dtype=dtype) +def data_for_twos(dtype): + return integer_array(np.ones(100) * 2, dtype=dtype) @pytest.fixture diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index a0f359f34d476..fb3c4e87abcf5 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -21,8 +21,8 @@ def data(dtype): @pytest.fixture -def data_for_ones(dtype): - return PeriodArray(np.ones(100), freq=dtype.freq) +def data_for_twos(dtype): + return PeriodArray(np.ones(100) * 2, freq=dtype.freq) @pytest.fixture diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index ce8b39d6c72c8..3e1186f59478f 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -35,8 +35,8 @@ def data(request): @pytest.fixture -def data_for_ones(request): - return SparseArray(np.ones(100)) +def data_for_twos(request): + return SparseArray(np.ones(100) * 2) @pytest.fixture(params=[0, np.nan]) From 9fd8b084a3322478e7dbb84e6f9d9a2391fe714f Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 10 Mar 2019 11:58:51 +0800 Subject: [PATCH 4/5] Amend after review --- pandas/tests/extension/conftest.py | 6 ++++++ pandas/tests/extension/json/test_json.py | 2 ++ pandas/tests/extension/test_categorical.py | 2 ++ 3 files changed, 10 insertions(+) diff --git a/pandas/tests/extension/conftest.py b/pandas/tests/extension/conftest.py index 3cc2d313b09f5..b6e839f250e4e 100644 --- a/pandas/tests/extension/conftest.py +++ b/pandas/tests/extension/conftest.py @@ -21,6 +21,12 @@ def data(): raise NotImplementedError +@pytest.fixture +def data_for_twos(): + """Length-100 array in which all the elements are two.""" + raise NotImplementedError + + @pytest.fixture def data_missing(): """Length-2 array with [NA, Valid]""" diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index f91b8ecd2b38e..8c7e99b7d0cc5 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -291,6 +291,8 @@ def test_add_series_with_extension_array(self, data): ser + data def test_divmod_series_array(self): + # GH 23287 + # skipping because it is not implemented pass def _check_divmod_op(self, s, op, other, exc=NotImplementedError): diff --git a/pandas/tests/extension/test_categorical.py b/pandas/tests/extension/test_categorical.py index 335537269df4a..9871d0d8f96f5 100644 --- a/pandas/tests/extension/test_categorical.py +++ b/pandas/tests/extension/test_categorical.py @@ -215,6 +215,8 @@ def test_add_series_with_extension_array(self, data): ser + data def test_divmod_series_array(self): + # GH 23287 + # skipping because it is not implemented pass def _check_divmod_op(self, s, op, other, exc=NotImplementedError): From 6d80b58ab440bb72414d8190e33dee3a5aababc8 Mon Sep 17 00:00:00 2001 From: makbigc Date: Sat, 16 Mar 2019 19:41:01 +0800 Subject: [PATCH 5/5] Add test_divmod_series_array in test_datetime.py --- pandas/tests/extension/test_datetime.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index 00ad35bf6a924..e3fdd0db3e8b4 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -147,6 +147,11 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators): def test_error(self, data, all_arithmetic_operators): pass + def test_divmod_series_array(self): + # GH 23287 + # skipping because it is not implemented + pass + @pytest.mark.xfail(reason="different implementation", strict=False) def test_direct_arith_with_series_returns_not_implemented(self, data): # Right now, we have trouble with this. Returning NotImplemented