We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
Input:
print(pd.to_datetime(['2001']).to_series().dt.to_period('D').dtype) print(pd.to_datetime(['NaT']).to_series().dt.to_period('D').dtype)
Output:
object datetime64[ns]
Calling .dt.to_period on an all-NaT series will return datetimes, not periods. This can easily cause programs to crash on unexpected inputs.
.dt.to_period
object object
pd.show_versions()
commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 4.14.14-200.fc26.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: C LANG: C LOCALE: None.None
pandas: 0.23.0 pytest: 3.5.1 pip: 10.0.1 setuptools: 39.1.0 Cython: 0.28.2 numpy: 1.13.3 scipy: 0.19.1 pyarrow: None xarray: None IPython: 4.2.1 sphinx: 1.7.4 patsy: 0.5.0 dateutil: 2.7.2 pytz: 2018.4 blosc: None bottleneck: 1.2.1 tables: 3.4.3 numexpr: 2.6.2 feather: None matplotlib: 2.2.2 openpyxl: None xlrd: 1.1.0 xlwt: None xlsxwriter: None lxml: None bs4: 4.6.0 html5lib: 1.0.1 sqlalchemy: 1.2.7 pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: 0.1.5 pandas_gbq: None pandas_datareader: None
The text was updated successfully, but these errors were encountered:
This looks fixed on master (as Series now supports period types). Could use a test.
In [40]: print(pd.to_datetime(['2001']).to_series().dt.to_period('D').dtype) ...: print(pd.to_datetime(['NaT']).to_series().dt.to_period('D').dtype) period[D] period[D] In [41]: pd.__version__ Out[41]: '0.24.0rc1+1.g33f91d8f9'
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Uh oh!
There was an error while loading. Please reload this page.
Code Sample, a copy-pastable example if possible
Input:
Output:
Problem description
Calling
.dt.to_period
on an all-NaT series will return datetimes, not periods. This can easily cause programs to crash on unexpected inputs.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.14-200.fc26.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: C
LOCALE: None.None
pandas: 0.23.0
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 4.2.1
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.2
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: