-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Converting series of dates to Periods #23438
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
Comments
@thequackdaddy : Thanks for reporting this! Can you tell us which version it this last worked? |
It works in 0.23.4 |
#22862 introduced the error messages that are breaking in the code sample, but it's likely not the breaking commit since this is an error path... |
Marking this for |
Your
|
See below |
@gfyoung : I get the same error as @mroeschke when trying to use the I think raising an error is the correct behavior based on the docs for I can replicate the On 0.23.4: In [1]: import pandas as pd; pd.__version__
Out[1]: '0.23.4'
In [2]: dates = pd.Series(pd.date_range('2014-01-01', '2017-01-01', freq='MS'))
In [3]: dates.to_period('M').head()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-2563b9c17104> in <module>()
----> 1 dates.to_period('M').head()
~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in to_period(self, freq, copy)
3958 new_values = new_values.copy()
3959
-> 3960 new_index = self.index.to_period(freq=freq)
3961 return self._constructor(new_values,
3962 index=new_index).__finalize__(self)
AttributeError: 'RangeIndex' object has no attribute 'to_period'
In [4]:
In [4]: dates.dt.to_period('M').head()
Out[4]:
0 2014-01
1 2014-02
2 2014-03
3 2014-04
4 2014-05
dtype: object On master: In [1]: import pandas as pd; pd.__version__
Out[1]: '0.24.0.dev0+879.g9019582'
In [2]: dates = pd.Series(pd.date_range('2014-01-01', '2017-01-01', freq='MS'))
In [3]: dates.to_period('M')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-944b687ce2da> in <module>()
----> 1 dates.to_period('M')
~/code/pandas/pandas/core/series.py in to_period(self, freq, copy)
4108 new_values = new_values.copy()
4109
-> 4110 new_index = self.index.to_period(freq=freq)
4111 return self._constructor(new_values,
4112 index=new_index).__finalize__(self)
AttributeError: 'RangeIndex' object has no attribute 'to_period'
In [4]: dates.dt.to_period('M').head()
Out[4]:
0 2014-01
1 2014-02
2 2014-03
3 2014-04
4 2014-05
dtype: period[M] |
@mroeschke @jschendel : Ah, so I see where we're getting confused. There are two lines of code that are breaking:
I agree that |
I think |
Code Sample, a copy-pastable example if possible
Problem description
A pandas series of datetimes can't be easily converted to PeriodIndexes anymore. These work under older versions of pandas, but fail now on GitHub's master.
Expected Output
Just don't fail...
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 18.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.0.dev0+850.g62a15fa40
pytest: 3.9.3
pip: 18.1
setuptools: 40.5.0
Cython: 3.0a0
numpy: 1.16.0.dev0+45718fd
scipy: 1.2.0.dev0+016a6ef
pyarrow: None
xarray: None
IPython: 7.1.1
sphinx: None
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.6
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: