Skip to content

Commit 50960d8

Browse files
BUG: Redefine IndexOpsMixin.size, fix #25580. (#25584) (#25667)
Signed-off-by: HE, Tao <[email protected]> (cherry picked from commit 6375549)
1 parent 42d4750 commit 50960d8

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

doc/source/whatsnew/v0.24.2.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ Bug Fixes
102102
- Bug in :meth:`Series.is_unique` where single occurrences of ``NaN`` were not considered unique (:issue:`25180`)
103103
- 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`)
104104
- 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`)
105-
-
105+
- Bug in :attr:`Series.size` raising for some extension-array-backed ``Series``, rather than returning the size (:issue:`25580`)
106+
- Bug in resampling raising for nullable integer-dtype columns (:issue:`25580`)
106107

107108
.. _whatsnew_0242.contributors:
108109

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def size(self):
761761
"""
762762
Return the number of elements in the underlying data.
763763
"""
764-
return self._values.size
764+
return len(self._values)
765765

766766
@property
767767
def flags(self):

pandas/tests/resample/test_datetime_index.py

+12
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ def test_resample_basic(series, closed, expected):
102102
assert_series_equal(result, expected)
103103

104104

105+
def test_resample_integerarray():
106+
# GH 25580, resample on IntegerArray
107+
ts = pd.Series(range(9),
108+
index=pd.date_range('1/1/2000', periods=9, freq='T'),
109+
dtype='Int64')
110+
result = ts.resample('3T').sum()
111+
expected = Series([3, 12, 21],
112+
index=pd.date_range('1/1/2000', periods=3, freq='3T'),
113+
dtype="Int64")
114+
assert_series_equal(result, expected)
115+
116+
105117
def test_resample_basic_grouper(series):
106118
s = series
107119
result = s.resample('5Min').last()

pandas/tests/series/test_api.py

+7
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ def test_tab_complete_warning(self, ip):
493493
with provisionalcompleter('ignore'):
494494
list(ip.Completer.completions('s.', 1))
495495

496+
def test_integer_series_size(self):
497+
# GH 25580
498+
s = Series(range(9))
499+
assert s.size == 9
500+
s = Series(range(9), dtype="Int64")
501+
assert s.size == 9
502+
496503

497504
class TestCategoricalSeries(object):
498505

0 commit comments

Comments
 (0)