Skip to content

Series: inconsistent behavior of setting value with timestamp dtype for existed index and newly-added #26031

New issue

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

Closed
ianzhy opened this issue Apr 9, 2019 · 8 comments
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions

Comments

@ianzhy
Copy link

ianzhy commented Apr 9, 2019

sample = pd.Series([1,2],index=['a','b'])
ts = pd.Timestamp('2019-01-01')
sample['a'] = ts
sample['c'] = ts
print(sample)

output:

a    2019-01-01 00:00:00
b                      2
c    1546300800000000000
dtype: object

Problem description

With existed index a, the dtype will be Timestamp, as expected. Howerver, when setting a new index like c, the dtype will be int.
Is this a bug?

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Darwin
OS-release: 18.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: zh_CN.UTF-8

pandas: 0.23.4
pytest: 4.0.2
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.15.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.2
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.2
openpyxl: 2.5.12
xlrd: 1.2.0
xlwt: 1.2.0
xlsxwriter: 1.1.2
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.15
pymysql: 0.9.3
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.7.0

@jreback
Copy link
Contributor

jreback commented Apr 9, 2019

try on 0.24.2 - irrc this is fixed

@WillAyd
Copy link
Member

WillAyd commented Apr 9, 2019

Looks like it's an issue on master. Investigation and PRs would certainly be welcome

@WillAyd WillAyd added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 9, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Apr 9, 2019
@WillAyd WillAyd added the Datetime Datetime data dtype label Apr 9, 2019
@ianzhy
Copy link
Author

ianzhy commented Apr 10, 2019

try on 0.24.2 - irrc this is fixed

@jreback Just tried on 0.24.2, and it's not fixed.
By the way, what does irrc mean?

@jreback
Copy link
Contributor

jreback commented Apr 10, 2019

pls try on master then

@robbuckley
Copy link
Contributor

this is fixed on master, and on releases from 0.25.0.
Output:

a    2019-01-01 00:00:00
b                      2
c    2019-01-01 00:00:00
dtype: object

so this can be closed @jreback @WillAyd

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Indexing Related to indexing on series/frames, not to indexes themselves Datetime Datetime data dtype labels Dec 8, 2019
@robbuckley
Copy link
Contributor

i'll take a look at adding a test for this @mroeschke

@robbuckley
Copy link
Contributor

this was fixed by PR #27303. This issue is really a duplicate of #22717

testing added there seems enough

def test_append_timedelta_does_not_cast(td):

@mroeschke
Copy link
Member

Thanks for digging in @robbuckley! Will close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

No branches or pull requests

5 participants