Skip to content

API: Index.str follow-ups (extract/get_dummies) #9980

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
sinhrks opened this issue Apr 24, 2015 · 3 comments
Closed

API: Index.str follow-ups (extract/get_dummies) #9980

sinhrks opened this issue Apr 24, 2015 · 3 comments
Labels
Strings String extension data type and string data
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Apr 24, 2015

Follow-ups for #9667. Noticed 2 methods which can return DataFrame.

1. Index.str.extract

As shown in docstring, it returns DataFrame when the expression has 2 or more groups.

pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)')
#0      1
#1      2
#2    NaN
# dtype: object

pd.Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
#      0    1
#0    a    1
#1    b    2
#2  NaN  NaN

Currently, Index.str.extract raises an error in both cases. I think 1st case should return Index, and 2nd case should raise understandable error.

pd.Index(['a1', 'b2', 'c3']).str.extract('[ab](\d)')
# AttributeError: 'Index' object has no attribute 'index'

pd.Index(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
# AttributeError: 'Index' object has no attribute 'empty'

2. Index.str.get_dummies

Because it returns DataFrame, should raise an understandable error.

pd.Index(['a1', 'b2', 'c3']).str.get_dummies()
# AttributeError: 'Index' object has no attribute 'fillna'

CC: @mortada

@sinhrks sinhrks added the Strings String extension data type and string data label Apr 24, 2015
@sinhrks sinhrks added this to the 0.16.1 milestone Apr 24, 2015
@mortada
Copy link
Contributor

mortada commented Apr 24, 2015

@sinhrks thanks I just noticed this too, I'm happy to submit a PR

@sinhrks
Copy link
Member Author

sinhrks commented Apr 24, 2015

@mortada Appreciated!

@jreback
Copy link
Contributor

jreback commented May 8, 2015

closed by #9985

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Strings String extension data type and string data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants