From 84bb45712aabe23fd3cc09ea49de5b7736dce47e Mon Sep 17 00:00:00 2001 From: Tao He Date: Tue, 12 Mar 2019 00:09:27 +0800 Subject: [PATCH] BUG: Redefine IndexOpsMixin.size, fix #25580. (#25584) Signed-off-by: HE, Tao (cherry picked from commit 63755498d82e9075826683983a907ce9b900b823) --- doc/source/whatsnew/v0.24.2.rst | 3 ++- pandas/core/base.py | 2 +- pandas/tests/resample/test_datetime_index.py | 12 ++++++++++++ pandas/tests/series/test_api.py | 7 +++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index 0f603515c61cc..ee9419c79e265 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -102,7 +102,8 @@ Bug Fixes - Bug in :meth:`Series.is_unique` where single occurrences of ``NaN`` were not considered unique (:issue:`25180`) - Bug in :func:`merge` when merging an empty ``DataFrame`` with an ``Int64`` column or a non-empty ``DataFrame`` with an ``Int64`` column that is all ``NaN`` (:issue:`25183`) - Bug in ``IntervalTree`` where a ``RecursionError`` occurs upon construction due to an overflow when adding endpoints, which also causes :class:`IntervalIndex` to crash during indexing operations (:issue:`25485`) -- +- Bug in :attr:`Series.size` raising for some extension-array-backed ``Series``, rather than returning the size (:issue:`25580`) +- Bug in resampling raising for nullable integer-dtype columns (:issue:`25580`) .. _whatsnew_0242.contributors: diff --git a/pandas/core/base.py b/pandas/core/base.py index 79b869c51d48f..061ec85f82047 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -761,7 +761,7 @@ def size(self): """ Return the number of elements in the underlying data. """ - return self._values.size + return len(self._values) @property def flags(self): diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 3f613c52a03f0..5a8a6b465c578 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -102,6 +102,18 @@ def test_resample_basic(series, closed, expected): assert_series_equal(result, expected) +def test_resample_integerarray(): + # GH 25580, resample on IntegerArray + ts = pd.Series(range(9), + index=pd.date_range('1/1/2000', periods=9, freq='T'), + dtype='Int64') + result = ts.resample('3T').sum() + expected = Series([3, 12, 21], + index=pd.date_range('1/1/2000', periods=3, freq='3T'), + dtype="Int64") + assert_series_equal(result, expected) + + def test_resample_basic_grouper(series): s = series result = s.resample('5Min').last() diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 1f2e2b179c687..3ad9d54175f31 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -493,6 +493,13 @@ def test_tab_complete_warning(self, ip): with provisionalcompleter('ignore'): list(ip.Completer.completions('s.', 1)) + def test_integer_series_size(self): + # GH 25580 + s = Series(range(9)) + assert s.size == 9 + s = Series(range(9), dtype="Int64") + assert s.size == 9 + class TestCategoricalSeries(object):