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(func) issue when func returns tuple #465

Closed
lodagro opened this issue Dec 9, 2011 · 2 comments
Closed

DataFrame.applymap(func) issue when func returns tuple #465

lodagro opened this issue Dec 9, 2011 · 2 comments
Labels
Milestone

Comments

@lodagro
Copy link
Contributor

lodagro commented Dec 9, 2011

In [82]: def func_tuple(x):
   ....:     return (x,x)
   ....:

In [83]: series = pandas.Series(['a', 'b', 'c', 'd'])

In [84]: df = pandas.DataFrame({'A': series})

In [85]: df
Out[85]:
   A
0  a
1  b
2  c
3  d

In [86]: df.applymap(func_tuple)
Out[86]:
   A
0  None
1  None
2  None
3  None

This works fine

In [87]: map(func_tuple, series)
Out[87]: [('a', 'a'), ('b', 'b'), ('c', 'c'), ('d', 'd')]

Let`s try with a list:

In [88]: def func_list(x):
   ....:     return [x,x]

In [89]: df.applymap(func_list)
Out[89]:
   A
0  ['a', 'a']
1  ['b', 'b']
2  ['c', 'c']
3  ['d', 'd']

Had a look at the pandas.DataFrame.applymap() code and this behavior is related to numpy.
I`m using numpy 1.5.1, i know that for other reason numpy 1.6.1 is preferred. Would more recent numpy version fix this?
I tried to install more recent version of numpy, but so far unsuccessful (various compilation errors).

In [103]: np.frompyfunc(func_tuple, 1, 1)(series)
Out[103]:
0    NaN
1    NaN
2    NaN
3    NaN

In [104]: np.frompyfunc(func_list, 1, 1)(series)
Out[104]:
0    ['a', 'a']
1    ['b', 'b']
2    ['c', 'c']
3    ['d', 'd']
@wesm
Copy link
Member

wesm commented Dec 12, 2011

This looks buggy enough to me...will see if I can sort out a fix here

@wesm wesm closed this as completed in 6aa80f9 Dec 12, 2011
@wesm
Copy link
Member

wesm commented Dec 12, 2011

Fixed in the above commit...turns out I'd written a frompyfunc replacement with type inference a few weeks ago that's pretty fast

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