Skip to content

Commit 9b28888

Browse files
BUG: Fix MultiIndex construction in pd.concat() with Int64Dtype NA
1 parent a8bcf68 commit 9b28888

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ Interval
11321132

11331133
Indexing
11341134
^^^^^^^^
1135+
- Bug in :func:`pandas.concat` incorrectly constructing the :class:`MultiIndex` when an inner level contained :obj:`pandas.NA` with :class:`pandas.Int64Dtype`, causing a :exc:`KeyError` on lookup (:issue:`62903`)
11351136
- Bug in :meth:`DataFrame.__getitem__` returning modified columns when called with ``slice`` in Python 3.12 (:issue:`57500`)
11361137
- Bug in :meth:`DataFrame.__getitem__` when slicing a :class:`DataFrame` with many rows raised an ``OverflowError`` (:issue:`59531`)
11371138
- Bug in :meth:`DataFrame.__setitem__` on an empty :class:`DataFrame` with a tuple corrupting the frame (:issue:`54385`)
@@ -1140,7 +1141,6 @@ Indexing
11401141
- Bug in :meth:`DataFrame.loc` with inconsistent behavior of loc-set with 2 given indexes to Series (:issue:`59933`)
11411142
- Bug in :meth:`Index.equals` when comparing between :class:`Series` with string dtype :class:`Index` (:issue:`61099`)
11421143
- Bug in :meth:`Index.get_indexer` and similar methods when ``NaN`` is located at or after position 128 (:issue:`58924`)
1143-
- Bug in :func:`pandas.concat` incorrectly constructing the :class:`MultiIndex` when an inner level contained :obj:`pandas.NA` with :class:`pandas.Int64Dtype`, causing a :exc:`KeyError` on lookup (:issue:`62903`)
11441144
- Bug in :meth:`MultiIndex.insert` when a new value inserted to a datetime-like level gets cast to ``NaT`` and fails indexing (:issue:`60388`)
11451145
- Bug in :meth:`Series.__setitem__` when assigning boolean series with boolean indexer will raise ``LossySetitemError`` (:issue:`57338`)
11461146
- Bug in printing :attr:`Index.names` and :attr:`MultiIndex.levels` would not escape single quotes (:issue:`60190`)

pandas/tests/indexes/multi/test_constructors.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,25 @@ def test_from_arrays_respects_none_names():
343343

344344
tm.assert_index_equal(result, expected)
345345

346+
346347
def test_concat_int64dtype_na_multiindex_lookup():
347-
levels1 = ['a', 'b']
348-
levels2 = pd.Series([1, 2, pd.NA], dtype=pd.Int64Dtype())
349-
index1 = MultiIndex.from_product([levels1, levels2], names=['one', 'two'])
350-
series1 = pd.Series([f'{i1}-{i2}' for i1, i2 in index1], index=index1)
348+
levels1 = ["a", "b"]
349+
levels2 = Series([1, 2, pd.NA], dtype=pd.Int64Dtype())
350+
index1 = MultiIndex.from_product([levels1, levels2], names=["one", "two"])
351+
series1 = Series([f"{i1}-{i2}" for i1, i2 in index1], index=index1)
351352
series2 = pd.concat(
352-
[series1.loc[i1] for i1 in levels1],
353-
keys=levels1,
354-
names=['one']
353+
[series1.loc[i1] for i1 in levels1], keys=levels1, names=["one"]
355354
)
356-
lookup_key = ('a', pd.NA)
355+
lookup_key = ("a", pd.NA)
357356
result = series2.at[lookup_key]
358-
assert result == 'a-<NA>'
357+
assert result == "a-<NA>"
359358
level_two = series2.index.levels[1]
360359
codes_two = series2.index.codes[1]
361360
assert level_two.hasnans is False
362361
assert codes_two[2] == -1
363362
assert codes_two[5] == -1
364363

364+
365365
# ----------------------------------------------------------------------------
366366
# from_tuples
367367
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)