We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
pd.DataFrame([pd.to_datetime('2018')]).dtypes # 0 datetime64[ns] # dtype: object (pd.DataFrame([pd.to_datetime('2018')]) + pd.DateOffset(years=1)).dtypes # 0 object # dtype: object
Timestamp + DateOffset = Timestamp, but DataFrame(datetime64[ns]) + DateOffset = DataFrame(object).
Timestamp
DateOffset
DataFrame(datetime64[ns])
DataFrame(object)
DataFrame(datetime64[ns]) + DateOffset = DataFrame(datetime64[ns]). Don't change dtype.
pd.show_versions()
[paste the output of pd.show_versions() here below this line]
commit: None python: 3.6.5.final.0 python-bits: 64 OS: Darwin OS-release: 17.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: zh_CN.UTF-8 LOCALE: zh_CN.UTF-8
pandas: 0.23.0 pytest: None pip: 10.0.1 setuptools: 39.2.0 Cython: None numpy: 1.14.5 scipy: 1.1.0 pyarrow: None xarray: None IPython: None sphinx: 1.6.2 patsy: None dateutil: 2.7.2 pytz: 2018.4 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 2.2.2 openpyxl: None xlrd: 1.0.0 xlwt: None xlsxwriter: None lxml: 3.8.0 bs4: 4.5.3 html5lib: 1.0.1 sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None
The text was updated successfully, but these errors were encountered:
Yeah, I guess the dispatch on this only works for Series, this should also work.
In [19]: df[0] = df[0] + pd.DateOffset(years=1) In [20]: df Out[20]: 0 0 2019-01-01 In [21]: df.dtypes Out[21]: 0 datetime64[ns] dtype: object
cc @jbrockmendel (anything open that already covers this?)
Sorry, something went wrong.
anything open that already covers this?
I don't think so. Just added a note to #18824.
pandas/pandas/core/internals.py
Lines 1359 to 1369 in 322dbf4
DateOffset is dtype object, a DatetimeBlock operated with object will cast to ObjectBlock.
object
DatetimeBlock
ObjectBlock
Besides, pd.DataFrame([pd.Timestamp('2018')]) + pd.Timedelta('1d') fails, but it seems easier to fix.
pd.DataFrame([pd.Timestamp('2018')]) + pd.Timedelta('1d')
Successfully merging a pull request may close this issue.
Code Sample, a copy-pastable example if possible
Problem description
Timestamp
+DateOffset
=Timestamp
, butDataFrame(datetime64[ns])
+DateOffset
=DataFrame(object)
.Expected Output
DataFrame(datetime64[ns])
+DateOffset
=DataFrame(datetime64[ns])
. Don't change dtype.Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 17.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: zh_CN.UTF-8
pandas: 0.23.0
pytest: None
pip: 10.0.1
setuptools: 39.2.0
Cython: None
numpy: 1.14.5
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: None
sphinx: 1.6.2
patsy: None
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.8.0
bs4: 4.5.3
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: