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

DataFrame.applymap with identity function changes dtype #2374

Closed
craustin opened this issue Nov 28, 2012 · 5 comments
Closed

DataFrame.applymap with identity function changes dtype #2374

craustin opened this issue Nov 28, 2012 · 5 comments
Assignees
Labels
Milestone

Comments

@craustin
Copy link

from datetime import datetime
from pandas import DataFrame
df = DataFrame({'x1': [datetime(1996,1,1)]})
df2 = df.applymap(lambda x: x)

Issue:
type(df['x1'][0]) == datetime.datetime
type(df2['x1'][0]) == pandas.lib.Timestamp

This repros in the 11/27/2012 cut of 0.10.0 - but not in 0.9.0 release.

@wesm
Copy link
Member

wesm commented Nov 28, 2012

Is there somewhere where Timestamp is causing you problems? It's a subclass of datetime.datetime and should be interchangeable

@craustin
Copy link
Author

Here's an unexpected crash:
from datetime import datetime
from pandas import DataFrame
from pandas.core.datetools import bday
df = DataFrame({'x1': [datetime(1996,1,1)]})
df = df.applymap(lambda x: x+bday)
df = df.applymap(lambda x: x+bday)

The first applymap succeeds (but alters the dtypes as in the above post). The second applymap raises this exception:

pandas\core\frame.pyc in applymap(self, func)
4114 applied : DataFrame
4115 """
-> 4116 return self.apply(lambda x: lib.map_infer(x, func))
4117
4118 #----------------------------------------------------------------------

pandas\core\frame.pyc in apply(self, func, axis, broadcast, raw, args, **kwds)
3981 return self._apply_raw(f, axis)
3982 else:
-> 3983 return self._apply_standard(f, axis)
3984 else:
3985 return self._apply_broadcast(f, axis)

pandas\core\frame.pyc in _apply_standard(self,
func, axis, ignore_failures)
4056 # no k defined yet
4057 pass
-> 4058 raise e
4059
4060 if len(results) > 0 and _is_sequence(results[0]):

TypeError: ("ufunc 'add' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule 'safe'", u'occurred at index x1')

@wesm
Copy link
Member

wesm commented Dec 7, 2012

I see the issue. Will get a fix in for 0.10

@ghost ghost assigned wesm Dec 7, 2012
@wesm wesm closed this as completed in b0a19c8 Dec 7, 2012
@wesm
Copy link
Member

wesm commented Dec 7, 2012

All set now

@craustin
Copy link
Author

craustin commented Dec 7, 2012

Great. Thanks Wes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants