Skip to content

Backport PR #25584 on branch 0.24.x (BUG: Redefine IndexOpsMixin.size, fix #25580) #25667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down