Skip to content

ENH: MultiIndex.from_frame #23141

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

Merged
merged 52 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
79bdecb
ENH - add from_frame method and accompanying squeeze method to multii…
sds9995 Oct 13, 2018
fa82618
ENH - guarentee that order of labels is preserved in multiindex to_fr…
sds9995 Oct 13, 2018
64b45d6
CLN - adhere to PEP8 line length
sds9995 Oct 13, 2018
64c7bb1
CLN - remove trailing whitespace
sds9995 Oct 13, 2018
3ee676c
ENH - raise TypeError on inappropriate input
sds9995 Oct 16, 2018
fd266f5
TST - add tests for mi.from_frame and mi.squeeze
sds9995 Oct 16, 2018
4bc8f5b
CLN - pep8 adherence in tests
sds9995 Oct 16, 2018
9d92b70
CLN - last missed pep8 fix
sds9995 Oct 16, 2018
45595ad
BUG - remove pd.DataFrame in favor of local import
ms7463 Oct 16, 2018
3530cd3
DOC - add more detailed docstrings for from_frame and squeeze
sds9995 Oct 18, 2018
1c22791
DOC - update MultiIndex.from_frame and squeeze doctests to comply wit…
sds9995 Oct 28, 2018
cf78780
CLN - cleanup docstrings and source
sds9995 Oct 28, 2018
64c2750
TST - reorganize some of the multiindex tests
sds9995 Oct 28, 2018
ede030b
CLN - adhere to pep8 line length
sds9995 Oct 28, 2018
190c341
BUG - ensure dtypes are preserved in from_frame and to_frame
sds9995 Nov 3, 2018
e0df632
TST - add tests for ensuring dtype fidelity and custom names for from…
sds9995 Nov 3, 2018
78ff5c2
CLN - pep8 adherence
sds9995 Nov 3, 2018
0252db9
DOC - add examples and change order of kwargs for from_frame
sds9995 Nov 3, 2018
d98c8a9
TST - parameterize tests
sds9995 Nov 3, 2018
8a1906e
CLN - pep8 adherence
sds9995 Nov 3, 2018
08c120f
CLN - pep8 adherence
sds9995 Nov 3, 2018
8353c3f
DOC/CLN - add versionadded tags, add to whatsnew page, and clean up i…
sds9995 Nov 4, 2018
9df3c11
CLN - squeeze -> _squeeze
sds9995 Nov 10, 2018
6d4915e
DOC - squeeze -> _squeeze in whatsnew
ms7463 Nov 10, 2018
b5df7b2
BUG - allow repeat column names in from_frame, and falsey column name…
sds9995 Nov 11, 2018
ab3259c
DOC - whatsnew formatting
sds9995 Nov 11, 2018
cf95261
TST - reorganize and add tests for more incompatible from_frame types
sds9995 Nov 11, 2018
63051d7
Merge branch 'enhancement/from_frame' of https://github.com/ArtinSarr…
sds9995 Nov 11, 2018
a75a4a5
CLN - remove squeeze tests
sds9995 Nov 12, 2018
8d23df9
CLN - remove squeeze parameter from from_frame
sds9995 Nov 12, 2018
c8d696d
Merge branch 'master' into enhancement/from_frame
sds9995 Nov 12, 2018
7cf82d1
TST - remove callable name option
sds9995 Nov 12, 2018
1a282e5
ENH - from_data initial commit
sds9995 Nov 14, 2018
b3c6a90
DOC - reduce whatsnew entry for to_frame
sds9995 Nov 19, 2018
c760359
CLN/DOC - add examples to from_frame docstring and make code more rea…
sds9995 Nov 19, 2018
bb69314
Merge branch 'master' into enhancement/from_frame
sds9995 Nov 19, 2018
9e11180
TST - use OrderedDict for dataframe construction
sds9995 Nov 20, 2018
96c6af3
Merge branch 'master' into enhancement/from_frame
sds9995 Nov 28, 2018
a5236bf
CLN - clean up code and use pytest.raises
sds9995 Dec 1, 2018
c78f364
Merge branch 'master' into enhancement/from_frame
sds9995 Dec 1, 2018
14bfea8
DOC - move to_frame breaking changes to backwards incompatible sectio…
sds9995 Dec 2, 2018
6960804
Merge branch 'master' into enhancement/from_frame
ms7463 Dec 2, 2018
11c5947
Merge branch 'master' into enhancement/from_frame
sds9995 Dec 4, 2018
904644a
Merge branch 'enhancement/from_frame' of https://github.com/ArtinSarr…
sds9995 Dec 4, 2018
30fe0df
DOC - add advanced.rst section
sds9995 Dec 5, 2018
ec60563
Merge branch 'master' into enhancement/from_frame
sds9995 Dec 5, 2018
8fc6609
Merge branch 'master' into enhancement/from_frame
sds9995 Dec 6, 2018
9b906c6
DOC/CLN - cleanup documentation
sds9995 Dec 6, 2018
e416122
CLN - fix linting error according to pandas-dev.pandas test
sds9995 Dec 6, 2018
4ef9ec4
DOC - fix docstrings
sds9995 Dec 7, 2018
4240a1e
CLN - fix import order with isort
sds9995 Dec 7, 2018
9159b2d
Merge branch 'master' into enhancement/from_frame
sds9995 Dec 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions doc/source/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ The :class:`MultiIndex` object is the hierarchical analogue of the standard
can think of ``MultiIndex`` as an array of tuples where each tuple is unique. A
``MultiIndex`` can be created from a list of arrays (using
:meth:`MultiIndex.from_arrays`), an array of tuples (using
:meth:`MultiIndex.from_tuples`), or a crossed set of iterables (using
:meth:`MultiIndex.from_product`). The ``Index`` constructor will attempt to return
:meth:`MultiIndex.from_tuples`), a crossed set of iterables (using
:meth:`MultiIndex.from_product`), or a :class:`DataFrame` (using
:meth:`MultiIndex.from_frame`). The ``Index`` constructor will attempt to return
a ``MultiIndex`` when it is passed a list of tuples. The following examples
demonstrate different ways to initialize MultiIndexes.

Expand All @@ -89,6 +90,19 @@ to use the :meth:`MultiIndex.from_product` method:
iterables = [['bar', 'baz', 'foo', 'qux'], ['one', 'two']]
pd.MultiIndex.from_product(iterables, names=['first', 'second'])

You can also construct a ``MultiIndex`` from a ``DataFrame`` directly, using
the method :meth:`MultiIndex.from_frame`. This is a complementary method to
:meth:`MultiIndex.to_frame`.

.. versionadded:: 0.24.0

.. ipython:: python

df = pd.DataFrame([['bar', 'one'], ['bar', 'two'],
['foo', 'one'], ['foo', 'two']],
columns=['first', 'second'])
pd.MultiIndex.from_frame(df)

As a convenience, you can pass a list of arrays directly into ``Series`` or
``DataFrame`` to construct a ``MultiIndex`` automatically:

Expand Down
1 change: 1 addition & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,7 @@ MultiIndex Constructors
MultiIndex.from_arrays
MultiIndex.from_tuples
MultiIndex.from_product
MultiIndex.from_frame

MultiIndex Attributes
~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ Backwards incompatible API changes
- Passing scalar values to :class:`DatetimeIndex` or :class:`TimedeltaIndex` will now raise ``TypeError`` instead of ``ValueError`` (:issue:`23539`)
- ``max_rows`` and ``max_cols`` parameters removed from :class:`HTMLFormatter` since truncation is handled by :class:`DataFrameFormatter` (:issue:`23818`)
- :meth:`read_csv` will now raise a ``ValueError`` if a column with missing values is declared as having dtype ``bool`` (:issue:`20591`)
- The column order of the resultant :class:`DataFrame` from :meth:`MultiIndex.to_frame` is now guaranteed to match the :attr:`MultiIndex.names` order. (:issue:`22420`)

.. _whatsnew_0240.api_breaking.deps:

Expand Down Expand Up @@ -1431,6 +1432,7 @@ MultiIndex

- Removed compatibility for :class:`MultiIndex` pickles prior to version 0.8.0; compatibility with :class:`MultiIndex` pickles from version 0.13 forward is maintained (:issue:`21654`)
- :meth:`MultiIndex.get_loc_level` (and as a consequence, ``.loc`` on a ``Series`` or ``DataFrame`` with a :class:`MultiIndex` index) will now raise a ``KeyError``, rather than returning an empty ``slice``, if asked a label which is present in the ``levels`` but is unused (:issue:`22221`)
- :cls:`MultiIndex` has gained the :meth:`MultiIndex.from_frame`, it allows constructing a :cls:`MultiIndex` object from a :cls:`DataFrame` (:issue:`22420`)
- Fix ``TypeError`` in Python 3 when creating :class:`MultiIndex` in which some levels have mixed types, e.g. when some labels are tuples (:issue:`15457`)

I/O
Expand Down
Loading