Skip to content

Commit 901fc64

Browse files
toobazTomAugspurger
authored andcommitted
Emit warning for missing labels in Multiindex.loc[[...]] (and more) (#20770)
* API: emit warning to raise KeyError in the future for missing keys also for MultiIndex closes #17758 closes #20748 closes #20753
1 parent 605582a commit 901fc64

File tree

10 files changed

+309
-174
lines changed

10 files changed

+309
-174
lines changed

doc/source/whatsnew/v0.23.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ Deprecations
874874
- The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`).
875875
- ``IntervalIndex.from_intervals`` is deprecated in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
876876
- ``DataFrame.from_items`` is deprecated. Use :func:`DataFrame.from_dict` instead, or ``DataFrame.from_dict(OrderedDict())`` if you wish to preserve the key order (:issue:`17320`, :issue:`17312`)
877+
- Indexing a :class:`MultiIndex` or a :class:`FloatIndex` with a list containing some missing keys will now show a :class:`FutureWarning`, which is consistent with other types of indexes (:issue:`17758`).
877878

878879
- The ``broadcast`` parameter of ``.apply()`` is deprecated in favor of ``result_type='broadcast'`` (:issue:`18577`)
879880
- The ``reduce`` parameter of ``.apply()`` is deprecated in favor of ``result_type='reduce'`` (:issue:`18577`)
@@ -1124,6 +1125,8 @@ Indexing
11241125
- :func:`Index.to_series` now accepts ``index`` and ``name`` kwargs (:issue:`18699`)
11251126
- :func:`DatetimeIndex.to_series` now accepts ``index`` and ``name`` kwargs (:issue:`18699`)
11261127
- Bug in indexing non-scalar value from ``Series`` having non-unique ``Index`` will return value flattened (:issue:`17610`)
1128+
- Bug in indexing with iterator containing only missing keys, which raised no error (:issue:`20748`)
1129+
- Fixed inconsistency in ``.ix`` between list and scalar keys when the index has integer dtype and does not include the desired keys (:issue:`20753`)
11271130
- Bug in ``__setitem__`` when indexing a :class:`DataFrame` with a 2-d boolean ndarray (:issue:`18582`)
11281131
- Bug in ``str.extractall`` when there were no matches empty :class:`Index` was returned instead of appropriate :class:`MultiIndex` (:issue:`19034`)
11291132
- Bug in :class:`IntervalIndex` where empty and purely NA data was constructed inconsistently depending on the construction method (:issue:`18421`)

pandas/core/indexes/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -4926,6 +4926,9 @@ def _ensure_index(index_like, copy=False):
49264926
if hasattr(index_like, 'name'):
49274927
return Index(index_like, name=index_like.name, copy=copy)
49284928

4929+
if is_iterator(index_like):
4930+
index_like = list(index_like)
4931+
49294932
# must check for exactly list here because of strict type
49304933
# check in clean_index_list
49314934
if isinstance(index_like, list):

0 commit comments

Comments
 (0)