Skip to content

Commit de071c6

Browse files
Backport PR pandas-dev#47349 on branch 1.4.x (REGR: MultiIndex.dtypes has regular Index instead of MultiIndex index) (pandas-dev#47369)
Backport PR pandas-dev#47349: REGR: MultiIndex.dtypes has regular Index instead of MultiIndex index Co-authored-by: Patrick Hoefler <[email protected]>
1 parent d268359 commit de071c6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v1.4.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ including other versions of pandas.
1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717
- Fixed regression in :meth:`DataFrame.replace` when the replacement value was explicitly ``None`` when passed in a dictionary to ``to_replace`` also casting other columns to object dtype even when there were no values to replace (:issue:`46634`)
18+
- Fixed regression in representation of ``dtypes`` attribute of :class:`MultiIndex` (:issue:`46900`)
1819
- Fixed regression when setting values with :meth:`DataFrame.loc` updating :class:`RangeIndex` when index was set as new column and column was updated afterwards (:issue:`47128`)
1920
- Fixed regression in :meth:`DataFrame.nsmallest` led to wrong results when ``np.nan`` in the sorting column (:issue:`46589`)
2021
- Fixed regression in :func:`read_fwf` raising ``ValueError`` when ``widths`` was specified with ``usecols`` (:issue:`46580`)

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def dtypes(self) -> Series:
741741
from pandas import Series
742742

743743
names = com.fill_missing_names([level.name for level in self.levels])
744-
return Series([level.dtype for level in self.levels], index=names)
744+
return Series([level.dtype for level in self.levels], index=Index(names))
745745

746746
def __len__(self) -> int:
747747
return len(self.codes[0])

pandas/tests/indexes/multi/test_constructors.py

+10
Original file line numberDiff line numberDiff line change
@@ -827,3 +827,13 @@ def test_multiindex_inference_consistency():
827827
mi = MultiIndex.from_tuples([(x,) for x in arr])
828828
lev = mi.levels[0]
829829
assert lev.dtype == object
830+
831+
832+
def test_dtype_representation():
833+
# GH#46900
834+
pmidx = MultiIndex.from_arrays([[1], ["a"]], names=[("a", "b"), ("c", "d")])
835+
result = pmidx.dtypes
836+
expected = Series(
837+
["int64", "object"], index=MultiIndex.from_tuples([("a", "b"), ("c", "d")])
838+
)
839+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)