Skip to content

Unify index and multindex (and possibly others) API #3268

Closed
@ghost

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 and Index.from_arrays are just MultiIndex.from_tuples and MultiIndex.from_arrays moved to classmethods of Index.
  • droplevel, ` just raises on Index (right? what would it mean?): API: implement droplevels() for flat index #21115
  • has_duplicates is straightforward
  • truncate should be equivalent to slicing
  • reorder_levels raises if not level=0 or name of index
  • equal_levels - straightforward
  • levshape - (len(ind),)
  • sortorder - None
  • get_loc_level - I think meaningless with tuple, raises whatever if not 0 or index name
  • is_lexsorted - doesn't need to change
  • is_lexosrted_tuple - doesn't need to change
  • is_monotonic_*
  • lexsort_depth - doesn't need to be changed at all
  • searchsorted
  • repeat
  • levels and labels 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignIndexingRelated to indexing on series/frames, not to indexes themselvesInternalsRelated to non-user accessible pandas implementationRefactorInternal refactoring of code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions