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

ENH: improve extract and get_dummies methods for Index.str (fix for #9980) #9985

Closed
wants to merge 2 commits into from

Conversation

mortada
Copy link
Contributor

@mortada mortada commented Apr 25, 2015

Closes #9980

result = Series([f(val)[0] for val in arr],
name=_get_single_group_name(regex),
index=arr.index, dtype=object)
if isinstance(arr, Index):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use StringMethods._wrap_result here?

@sinhrks sinhrks added API Design Strings String extension data type and string data labels Apr 26, 2015
@sinhrks sinhrks added this to the 0.16.1 milestone Apr 26, 2015
@sinhrks
Copy link
Member

sinhrks commented Apr 26, 2015

Thanks! Added "Closes ... " description to the body to automatically close the original issue.

I'll update #9843 once behavior is decided.

@jorisvandenbossche jorisvandenbossche changed the title ENH: improve extract and get_dummies methods for Index.str (fix for #998... ENH: improve extract and get_dummies methods for Index.str (fix for #9980) Apr 27, 2015
# only non-capturing groups
f = lambda: s.str.extract('(?:[AB]).*')
self.assertRaises(ValueError, f)
# Index only works with one regex group since
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the issue reference here as a comment

@jreback
Copy link
Contributor

jreback commented Apr 28, 2015

pls add a release note. lgtm otherwise

@mortada
Copy link
Contributor Author

mortada commented Apr 29, 2015

@jreback updated with release note and issue number as inline comment as you suggested

result = Index([f(val)[0] for val in arr],
name=_get_single_group_name(regex),
dtype=object)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its worthile to change _wrap_result to something like this:

def _wrap_result(self, result, **kwargs):
     if not isinstance(result, (Series, Index)):
         result = type(self.series)(result, **kwargs)
     .....

should work if expand=False

@jreback
Copy link
Contributor

jreback commented May 7, 2015

@mortada can you update/rebase. I believe you can use _wrap_result_expand to simplify the code a bit.

@mortada
Copy link
Contributor Author

mortada commented May 7, 2015

@jreback updated, I can squash the commits later but for now I want to showcase the difference between the two implementations. To simplify the code inside str_extract(), we'd need to pass the name argument down into _wrap_result()

if 'name' in kwargs:
name = kwargs['name']
else:
name = getattr(result, 'name', None) or self.series.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just do:

name = kwargs.get('name') or getattr(result,'name',None) or self.series.name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call ... will update

@jreback
Copy link
Contributor

jreback commented May 8, 2015

merged via e686387

thanks!

@jreback jreback closed this May 8, 2015
@mortada mortada deleted the str_methods_fix branch May 8, 2015 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: Index.str follow-ups (extract/get_dummies)
4 participants