Skip to content
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

BUG: setitem with at not inferring dtype correctly #6942

Closed
jreback opened this issue Apr 23, 2014 · 6 comments · Fixed by #45154
Closed

BUG: setitem with at not inferring dtype correctly #6942

jreback opened this issue Apr 23, 2014 · 6 comments · Fixed by #45154
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Apr 23, 2014

xref #14179
xref #12499
xref #18027

http://stackoverflow.com/questions/23250333/in-pandas-dataframe-after-i-set-an-entire-column-i-cant-update-another-column

but .loc works

In [50]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [51]: df.at[start,'timenow'] = datetime.today() # initial value

In [52]: df
Out[52]: 
                              timenow Live
2014-04-01 2014-04-23 12:42:38.883082  NaN

[1 rows x 2 columns]

In [53]: df._data
Out[53]: 
BlockManager
Items: Index([u'timenow', u'Live'], dtype='object')
Axis 1: <class 'pandas.tseries.index.DatetimeIndex'>
[2014-04-01]
Length: 1, Freq: D, Timezone: None
ObjectBlock: [timenow, Live], 2 x 1, dtype: object

In [54]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [55]: df.loc[start,'timenow'] = datetime.today() # initial value

In [56]: df
Out[56]: 
                              timenow Live
2014-04-01 2014-04-23 12:43:00.554915  NaT

[1 rows x 2 columns]

In [57]: df._data
Out[57]: 
BlockManager
Items: Index([u'timenow', u'Live'], dtype='object')
Axis 1: <class 'pandas.tseries.index.DatetimeIndex'>
[2014-04-01]
Length: 1, Freq: D, Timezone: None
DatetimeBlock: [timenow, Live], 2 x 1, dtype: datetime64[ns]

@jreback jreback added this to the 0.15.0 milestone Apr 23, 2014
@jreback jreback changed the title BUG: setitem with at not inferring dtype updates correctly BUG: setitem with at not inferring dtype correctly Apr 23, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@jreback jreback modified the milestones: Next Major Release, 0.21.1, 0.22.0 Oct 30, 2017
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.23.0, 0.24.0 Mar 29, 2018
@jreback jreback modified the milestones: 0.24.0, Contributions Welcome Oct 23, 2018
@heaven00
Copy link

heaven00 commented Oct 24, 2018

Hey, I am gonna give it a shot 👍

EDIT1: The behaviour on the StackOverflow link isn't replicated with the current build

In [1]: import pandas as pd

In [2]: from datetime import datetime

In [3]: start = pd.to_datetime('20140401')

In [4]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [5]: df.at[start,'timenow'] = datetime.today() # initial value

In [6]: df
Out[6]: 
                               timenow Live
2014-04-01  2018-10-24 16:39:27.734368  NaN

In [7]: df.at[start,'timenow'] = datetime.today() # this works

In [8]: df
Out[8]: 
                               timenow Live
2014-04-01  2018-10-24 16:39:36.485698  NaN

In [9]: df.Live = True

In [10]: df.at[start,'timenow'] = datetime.today() # this doesn't work - nothing changes

In [11]: df
Out[11]: 
                               timenow  Live
2014-04-01  2018-10-24 16:39:55.149644  True

Also can you elaborate on the dtype not infered correctly?

@mroeschke
Copy link
Member

This looks to be working on master. Could use a test.

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug labels Sep 29, 2019
@anirudnits
Copy link
Contributor

@mroeschke I am working on this.
I have added the test test_datetimeField_after_setitem in pandas/tests/generic/test_frame.py and basically recorded the times after each operation(as mentioned in the above snippet) and asserted that neither of them are equal.
Seems good?

@mroeschke
Copy link
Member

Sure, will be easier to review in a PR

@anirudnits
Copy link
Contributor

@mroeschke sure I'll submit the PR soon.

@anirudnits
Copy link
Contributor

@mroeschke submitted the PR, have a look.

@simonjayhawkins simonjayhawkins removed Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 25, 2020
@mroeschke mroeschke added Bug Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Tests Unit test(s) needed to prevent regressions good first issue labels May 8, 2021
@jreback jreback modified the milestones: Contributions Welcome, 1.4 Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
6 participants