Timestamp incorrectly handles datetime64 with exotic units
See original GitHub issueCode Sample, a copy-pastable example if possible
>>> pd.Timestamp(np.datetime64('2019-01-01', '6h'))
Timestamp('1978-03-02 20:00:00')
Problem description
The pd.Timestamp
constructor gives the wrong result when converting a np.datetime64
that uses multiples of a standard unit. In the example above, I create a datetime64 with units of 6h
but the conversion appears to assume units of s
.
This happens with units of 6h
but not with units of h
:
>>> pd.Timestamp(np.datetime64('2019-01-01', 'h'))
Timestamp('2019-01-01 00:00:00')
Expected Output
Pandas should either perform a correct conversion or raise a value error:
>>> pd.Timestamp(np.datetime64('2019-01-01', '6h'))
Timestamp('2019-01-01 00:00:00')
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None python: 3.6.7.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-134-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8
pandas: 0.24.1 pytest: None pip: 19.0.3 setuptools: 40.8.0 Cython: None numpy: 1.16.2 scipy: 1.2.1 pyarrow: None xarray: 0.11.3 IPython: None sphinx: 1.8.4 patsy: None dateutil: 2.8.0 pytz: 2018.9 blosc: None bottleneck: 1.2.1 tables: None numexpr: None feather: None matplotlib: 3.0.3 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml.etree: 4.3.2 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Does this issue still need work? I would be happy to look into this further and work on the error message as previously mentioned.
Not sure we want to do a lot to support these multiple units, but at minimum should raise an error message - thanks for the report!