Skip to content

dtype changed when DataFrame add DateOffset #21610

Closed
@holymonson

Description

@holymonson

Code Sample, a copy-pastable example if possible

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

Problem description

Timestamp + DateOffset = Timestamp, but DataFrame(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsDatetimeDatetime data dtypeTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions