Skip to content

.apply converting string to date #9477

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
ashishsingal1 opened this issue Feb 12, 2015 · 2 comments · Fixed by #9501
Closed

.apply converting string to date #9477

ashishsingal1 opened this issue Feb 12, 2015 · 2 comments · Fixed by #9501
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@ashishsingal1
Copy link
Contributor

The .apply on DataFrame is converting my string to a date. I have posted this on StackOverflow:

http://stackoverflow.com/questions/28487105/pandas-on-apply-passing-wrong-value

I'm not sure if I'm doing something wrong or it is a bug, but it seems quite strange behavior.

Example here

In [8]: df = pd.DataFrame({'wing1':wing1, 'wing2':wing2, 'mat':mat}, index=belly)

In [9]: df
Out[9]: 
            mat wing1 wing2
216  2016-01-22  2T15   416
3T19 2019-09-07  4H19  4T20

In [17]: df.loc['3T19']
Out[17]: 
mat     2019-09-07 00:00:00
wing1   2015-02-16 04:19:00
wing2   2015-04-20 00:00:00
Name: 3T19, dtype: datetime64[ns]

In [18]: df.loc['216']
Out[18]: 
mat      2016-01-22 00:00:00
wing1                   2T15
wing2                    416
Name: 216, dtype: object
@jreback
Copy link
Contributor

jreback commented Feb 12, 2015

The converter is a little too agressive here as it should not try to convert this when the dtype is specified (as 'NOV' as a string is a valid datetime) and since there is another datetime it will try to coerce.
This should be passing False rather than True to the _try_cast here

In [2]: Series([Timestamp('20130101'),'NOV'],dtype=object)
Out[2]: 
0   2013-01-01
1   2015-11-12
dtype: datetime64[ns]

not sure what else might break though

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Feb 12, 2015
@jreback jreback added this to the 0.16.0 milestone Feb 12, 2015
@jreback
Copy link
Contributor

jreback commented Feb 12, 2015

@ashishsingal1 pull-requests are welcome to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants