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: Index to act like Series for common ops (DataFrame.index.max() crashes) #4551

Closed
ohadle opened this issue Aug 13, 2013 · 5 comments · Fixed by #6380
Closed

ENH: Index to act like Series for common ops (DataFrame.index.max() crashes) #4551

ohadle opened this issue Aug 13, 2013 · 5 comments · Fixed by #6380
Assignees
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation
Milestone

Comments

@ohadle
Copy link

ohadle commented Aug 13, 2013

related #4056, #5202, #5502, #5519, #6027

I have a DataFrame of length 390,080, with int64 indices.
df.index.size gives the correct answer of 390,080, but df.index.max results in a huge traceback that ends with:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/common.pyc in pprint_thing(thing, _nest_lvl, escape_chars, default_escapes, quote_strings)
   2051             hasattr(thing, 'next'):
   2052         return unicode(thing)
-> 2053     elif (isinstance(thing, dict) and
   2054           _nest_lvl < get_option("display.pprint_nest_depth")):
   2055         result = _pprint_dict(thing, _nest_lvl,quote_strings=True)

RuntimeError: maximum recursion depth exceeded in __instancecheck__

Using pandas 0.12.

@jreback
Copy link
Contributor

jreback commented Aug 13, 2013

there was an issue somewhere about this but can't find it....so will mark this as the issue

these common ops are not enabled directly on indices, but you can do:

In [7]: i = pd.Index(np.arange(400000))

In [8]: i.values.max()
Out[8]: 399999

In [9]: i.to_series().max()
Out[9]: 399999

@jtratner
Copy link
Contributor

seems like a good idea (and, frankly, you could almost make index inherit from ND Frame too, just blocking mutable ops. Just be careful not to introduce ops that would mutate series in place (obviously fine if it returns a copy)

@jreback
Copy link
Contributor

jreback commented Aug 13, 2013

actually I think what we could do is have a mixin class for certain ops

eg max,min prob most of them which apply to both series and index (they need slightly different handling internally)

@jtratner
Copy link
Contributor

@jreback yeah, probably better to selectively enhance rather than selectively downgrade (and potentially mess up instance checks, etc)

@jreback
Copy link
Contributor

jreback commented Sep 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants