Skip to content

Commit 2d44804

Browse files
committed
API: emit warning to raise KeyError in the future for missing keys also for MultiIndex
closes pandas-dev#17758 closes pandas-dev#20748 closes pandas-dev#20753
1 parent 3a2e9e6 commit 2d44804

File tree

7 files changed

+194
-131
lines changed

7 files changed

+194
-131
lines changed

doc/source/whatsnew/v0.23.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ Deprecations
866866
- The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`).
867867
- ``IntervalIndex.from_intervals`` is deprecated in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
868868
- ``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`)
869+
- Indexing a ``MultiIndex`` or a ``FloatIndex`` with a list containing some missing keys will now show a ``FutureWarning``, consistently with other types of indexes (:issue:`17758`).
869870

870871
- The ``broadcast`` parameter of ``.apply()`` is deprecated in favor of ``result_type='broadcast'`` (:issue:`18577`)
871872
- The ``reduce`` parameter of ``.apply()`` is deprecated in favor of ``result_type='reduce'`` (:issue:`18577`)
@@ -1102,6 +1103,8 @@ Indexing
11021103
- :func:`Index.to_series` now accepts ``index`` and ``name`` kwargs (:issue:`18699`)
11031104
- :func:`DatetimeIndex.to_series` now accepts ``index`` and ``name`` kwargs (:issue:`18699`)
11041105
- Bug in indexing non-scalar value from ``Series`` having non-unique ``Index`` will return value flattened (:issue:`17610`)
1106+
- Bug in indexing with iterator containing only missing keys, which raised no error (:issue:`20748`)
1107+
- Fixed inconsistency in ``.ix`` between list and scalar keys when index has integer dtype and does not include desired key(s) (:issue:`20753`)
11051108
- Bug in ``__setitem__`` when indexing a :class:`DataFrame` with a 2-d boolean ndarray (:issue:`18582`)
11061109
- Bug in ``str.extractall`` when there were no matches empty :class:`Index` was returned instead of appropriate :class:`MultiIndex` (:issue:`19034`)
11071110
- 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
@@ -4881,6 +4881,9 @@ def _ensure_index(index_like, copy=False):
48814881
if hasattr(index_like, 'name'):
48824882
return Index(index_like, name=index_like.name, copy=copy)
48834883

4884+
if is_iterator(index_like):
4885+
index_like = list(index_like)
4886+
48844887
# must check for exactly list here because of strict type
48854888
# check in clean_index_list
48864889
if isinstance(index_like, list):

0 commit comments

Comments
 (0)