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

Comments

@craustin
Copy link

commented Nov 28, 2012

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented Nov 28, 2012

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

This comment has been minimized.

Copy link
Member

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 in b0a19c8 Dec 7, 2012

@wesm

This comment has been minimized.

Copy link
Member

commented Dec 7, 2012

All set now

@craustin

This comment has been minimized.

Copy link
Author

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
Projects
None yet
2 participants
You can’t perform that action at this time.