Repository: pandas-dev/pandas
Pull request: BUG: Redefine IndexOpsMixin.size, fix #25580.


- [x] closes #25580
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Problem statement:
Int64 series resampling
#### Code Sample, a copy-pastable example if possible

```python
>>> import pandas as pd
>>> index = pd.date_range('1/1/2000', periods=9, freq='T')
>>> series = pd.Series(range(9), index=index, dtype='Int64')             
>>> series.resample('3T').sum()

AttributeError: 'IntegerArray' object has no attribute 'size'
```
#### Problem description
Pandas series with an Int64 dtype can not be resampled, instead raising an AttributeError because they have no size method. If the series is accessed as part of a DataFrame, e.g. 'df.resample('3T').series.mean()', it is successful.
It can also be fixed by adding a 'size' method to the IntegerArray class, e.g. 
```python
def size(self): 
    return self._data.size()
```
#### Expected Output
2000-01-01 00:00:00    1
2000-01-01 00:03:00    4
2000-01-01 00:06:00    7
Freq: 3T, dtype: Int64

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-43-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.1
pytest: 4.1.1
pip: 18.1
setuptools: 40.2.0
Cython: 0.29.2
numpy: 1.16.1
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: 1.8.3
patsy: 0.5.1
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: 1.0.1
sqlalchemy: 1.2.15
pymysql: None
psycopg2: 2.7.7 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: 0.2.0
fastparquet: 0.1.6
pandas_gbq: None
pandas_datareader: None
gcsfs: None

</details>

Hints from issue discussion:

Commit message: Fix a mistake, add a test case for `size` and revise whatsnew.

Signed-off-by: HE, Tao <sighingnow@gmail.com>

Patch to review:
diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst
index 4ca9d57f3a2e5..74026aabbf751 100644
--- a/doc/source/whatsnew/v0.24.2.rst
+++ b/doc/source/whatsnew/v0.24.2.rst
@@ -31,6 +31,7 @@ Fixed Regressions
 - Fixed regression in ``IntervalDtype`` construction where passing an incorrect string with 'Interval' as a prefix could result in a ``RecursionError``. (:issue:`25338`)
 - Fixed regression in :class:`Categorical`, where constructing it from a categorical ``Series`` and an explicit ``categories=`` that differed from that in the ``Series`` created an invalid object which could trigger segfaults. (:issue:`25318`)
 - Fixed pip installing from source into an environment without NumPy (:issue:`25193`)
+- Fixed bug where :meth:`Index.size` could not return correct result for :class:`api.extensions.ExtensionArray` (:issue:`25580`)
 
 .. _whatsnew_0242.enhancements:
 
diff --git a/pandas/core/base.py b/pandas/core/base.py
index f896596dd5216..8a57904aecce4 100644
--- a/pandas/core/base.py
+++ b/pandas/core/base.py
@@ -762,7 +762,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 ce675893d9907..ec05595536de4 100644
--- a/pandas/tests/resample/test_datetime_index.py
+++ b/pandas/tests/resample/test_datetime_index.py
@@ -101,6 +101,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):
 


Code review comments:
diff_hunk: @@ -31,6 +31,7 @@ Fixed Regressions
 - Fixed regression in ``IntervalDtype`` construction where passing an incorrect string with 'Interval' as a prefix could result in a ``RecursionError``. (:issue:`25338`)
 - Fixed regression in :class:`Categorical`, where constructing it from a categorical ``Series`` and an explicit ``categories=`` that differed from that in the ``Series`` created an invalid object which could trigger segfaults. (:issue:`25318`)
 - Fixed pip installing from source into an environment without NumPy (:issue:`25193`)
+- Fixed bug where :meth:`Index.size` could not return correct result for :class:`api.extensions.ExtensionArray` (:issue:`25580`)
path: doc/source/whatsnew/v0.24.2.rst
text: @user1:
this is not correct, it raised previously ot 'returned an incorrect value'

@user1:
this is also a bug fix and not a regression, can you move to the appopriate section (bug fixes numeric is ok)

@user1:
actually move to resampling bug fixes is good (you could mention that in the whatsnew note)