Inconsistent return type for downsampling on resample of empty DataFrame · Issue #14962 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
df1 = pd.DataFrame(dict(a=range(100)), index=pd.date_range('1/1/2000', periods=100, freq="M")) df2 = df1[df1.a < 0] df1.shape (100, 1) df2.shape (0, 1) df2.empty True type(df1.resample("Q").size()) <class 'pandas.core.series.Series'> type(df2.resample("Q").size()) <class 'pandas.core.frame.DataFrame'>
Problem description
Code that is resampling a DataFrame that also has some filtering should be able to expect consistent types. My specific case of this causing a problem was that the size()
output was being forwarded on to other code using Series.tolist()
, which obviously fails when the output is a DataFrame.
Expected Output
Expectation is that .size()
should always return a Series
.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 3.16.0-4-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_CA.utf8
LOCALE: en_CA.UTF-8
pandas: 0.19.1
nose: None
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.11.2
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None