Skip to content

BUG: Frequency not set for empty Series #14320

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

Closed
jluttine opened this issue Sep 29, 2016 · 6 comments
Closed

BUG: Frequency not set for empty Series #14320

jluttine opened this issue Sep 29, 2016 · 6 comments
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@jluttine
Copy link

Pandas doesn't set frequency properly for empty series. This is probably related to #14313.

A small, complete example of the issue

It works for non-empty series:

>>> pd.Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]), data=[3]).asfreq('H').index
DatetimeIndex(['2016-09-29 11:00:00'], dtype='datetime64[ns]', freq='H')

But for empty series, freq is None:

>>> pd.Series(index=pd.DatetimeIndex([]), data=[]).asfreq('H').index
DatetimeIndex([], dtype='datetime64[ns]', freq=None)

Expected Output

I expected the following output:

>>> pd.Series(index=pd.DatetimeIndex([]), data=[]).asfreq('H').index
DatetimeIndex([], dtype='datetime64[ns]', freq='H')

Output of pd.show_versions()

## INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.5-gnu-1
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.19.0rc1
nose: 1.3.6
pip: 8.1.2
setuptools: 27.3.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.0.0
sphinx: 1.4.5
patsy: None
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.2
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.5.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.5.1
sqlalchemy: 1.0.15
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Sep 29, 2016

https://github.com/pydata/pandas/blob/master/pandas/tseries/resample.py#L1347

should do: obj._shallow_copy(freq=to_offset(freq))

@jreback jreback added Bug Datetime Datetime data dtype labels Sep 29, 2016
@jreback jreback added this to the Next Major Release milestone Sep 29, 2016
@jreback jreback changed the title Frequency not set for empty Series BUG: Frequency not set for empty Series Sep 29, 2016
@sahildua2305
Copy link
Contributor

sahildua2305 commented Oct 3, 2016

@jreback This will require defining _shallow_copy for Series right? Because as of now it gives error -

AttributeError: 'Series' object has no attribute '_shallow_copy'

@jreback
Copy link
Contributor

jreback commented Oct 3, 2016

no this is for an Index

@sahildua2305
Copy link
Contributor

I tried obj._shallow_copy(freq=to_offset(freq)) but it gets the above mentioned error.

@jreback
Copy link
Contributor

jreback commented Oct 3, 2016

create a copy of the obj then assign the series with a shallow copy

@sahildua2305
Copy link
Contributor

I got this one! I will write tests to verify the expected behavior and create a PR. Thanks 😄

sahildua2305 added a commit to sahildua2305/pandas that referenced this issue Oct 4, 2016
Add test to verify frequency for empty series

Update test to compare empty series behaviour
against normal series

Add entry in whatsnew 0.20.0
sahildua2305 added a commit to sahildua2305/pandas that referenced this issue Oct 13, 2016
Add test to verify frequency for empty series

Update test to compare empty series behaviour
against normal series

Add entry in whatsnew 0.20.0
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 3, 2017
@jreback jreback closed this as completed in 0b07b07 Mar 3, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#14320

Author: Sahil Dua <[email protected]>

Closes pandas-dev#14458 from sahildua2305/frequency-series-fix and squashes the following commits:

384e666 [Sahil Dua] BUG: Set frequency for empty Series
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
3 participants