Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
The creation of a pandas Series with any dtype other than timedelta64[ns]
is discarding values and setting the entire series to 0
's. Whereas numpy.array
and pd.TimeDelta
are correctly instantiating and preserving the passed values which can be retrieved by a type-cast too.
Code Sample, a copy-pastable example
>>> import pandas as pd
>>> pd.__version__
'1.1.0'
>>> pd.Series([1000000, 200000, 3000000], dtype='timedelta64[ns]')
0 0 days 00:00:00.001000
1 0 days 00:00:00.000200
2 0 days 00:00:00.003000
dtype: timedelta64[ns]
>>> pd.Series([1000000, 200000, 3000000], dtype='timedelta64[s]')
0 0 days
1 0 days
2 0 days
dtype: timedelta64[ns]
>>> pd.Series([1000000, 200000, 3000000], dtype='timedelta64[s]').astype('int')
0 0
1 0
2 0
dtype: int64
>>> pd.Series([1000000, 200000, 3000000], dtype='timedelta64[ns]').astype('int')
0 1000000
1 200000
2 3000000
dtype: int64
>>> import numpy as np
>>> np.array([1000000, 200000, 3000000], dtype='timedelta64[ns]')
array([1000000, 200000, 3000000], dtype='timedelta64[ns]')
>>> np.array([1000000, 200000, 3000000], dtype='timedelta64[s]')
array([1000000, 200000, 3000000], dtype='timedelta64[s]')
>>> np.array([1000000, 200000, 3000000], dtype='timedelta64[s]').astype('int')
array([1000000, 200000, 3000000])
>>> pd.Timedelta(10)
Timedelta('0 days 00:00:00.000000010')
>>> pd.Timedelta(10, unit='s')
Timedelta('0 days 00:00:10')
>>> pd.Timedelta(10, unit='ns')
Timedelta('0 days 00:00:00.000000010')
Problem description
The expected behaviour is Series initialization must be in-line with numpy array initialization in this case.
Expected Output
Output of pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 1.1.0
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None