Unify index and multindex (and possibly others) API · Issue #3268 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Have you ever written code that looks like this:
if isinstance(d.index, MultiIndex):
results = []
for l in d.index.levels:
for x in baz(l):
results.append(foo)
elif isinstance(d.index, Index):
for x in d.index:
foo
I've had to special case the handling of index vs. multindex several times in the past.
Conceptually, I should be able to treat index as a private case of MultIndex
with nlevels =1, and supporting that in the API would make things nicer.
Edit by @cpcloud:
Tasks :
API Unification
Method unification is relatively simple:
Index.from_tuples
andIndex.from_arrays
are justMultiIndex.from_tuples
andMultiIndex.from_arrays
moved to classmethods ofIndex
.droplevel
, ` just raises on Index (right? what would it mean?): API: implement droplevels() for flat index #21115has_duplicates
is straightforwardtruncate
should be equivalent to slicingreorder_levels
raises if not level=0 or name of indexequal_levels
- straightforwardlevshape
- (len(ind),)sortorder
- Noneget_loc_level
- I think meaningless with tuple, raises whatever if not 0 or index nameis_lexsorted
- doesn't need to changeis_lexosrted_tuple
- doesn't need to changeis_monotonic_*
lexsort_depth
- doesn't need to be changed at allsearchsorted
repeat
levels
andlabels
property for Index - question on whether it should be sorted.- change to
rename
behavior:Index
will accept either string or single-element list; MI continues to handle only list