Skip to content

Cannot subclass MultiIndex #11267

@janmedlock

Description

@janmedlock

MultiIndex cannot be subclassed because in several spots, including __new__, the output class is hardcoded as MultiIndex rather than cls or self.__class__ or the like.

This code illustrates the problem:

$ python Python 2.7.10 (default, Sep 13 2015, 20:30:50) [GCC 5.2.1 20150911] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pandas >>> class MyMultiIndex(pandas.MultiIndex): ... pass ... >>> multiindex = MyMultiIndex([['a'], ['b']], ... [[0], [0]]) >>> print type(multiindex) <class 'pandas.core.index.MultiIndex'>

The last line should instead read

<class '__main__.MyMultiIndex'>

I have a patch in the works.

>>> pandas.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 2.7.10.final.0 python-bits: 64 OS: Linux OS-release: 4.1.0-2-amd64 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.utf8 pandas: 0.16.2.dev nose: 1.3.6 Cython: 0.23.2 numpy: 1.9.2 scipy: 0.14.1 statsmodels: 0.6.1 IPython: 2.3.0 sphinx: 1.3.1 patsy: 0.4.0 dateutil: 2.2 pytz: 2012c bottleneck: None tables: 3.1.1 numexpr: 2.4.3 matplotlib: 1.4.2 openpyxl: None xlrd: 0.9.4 xlwt: 0.7.5 xlsxwriter: None lxml: None bs4: 4.4.0 html5lib: 0.999 httplib2: 0.9.1 apiclient: None sqlalchemy: None pymysql: None psycopg2: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions