Skip to content

Commit 9ec8270

Browse files
committed
API: emit warning to raise KeyError in the future for missing keys also for MultiIndex
closes #17758 closes #20748 closes #20753
1 parent 0ae7e90 commit 9ec8270

File tree

7 files changed

+197
-131
lines changed

7 files changed

+197
-131
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ Deprecations
873873
- The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`).
874874
- ``IntervalIndex.from_intervals`` is deprecated in favor of the :class:`IntervalIndex` constructor (:issue:`19263`)
875875
- ``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`)
876+
- 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`).
876877

877878
- The ``broadcast`` parameter of ``.apply()`` is deprecated in favor of ``result_type='broadcast'`` (:issue:`18577`)
878879
- The ``reduce`` parameter of ``.apply()`` is deprecated in favor of ``result_type='reduce'`` (:issue:`18577`)
@@ -1107,6 +1108,8 @@ Indexing
11071108
- :func:`Index.to_series` now accepts ``index`` and ``name`` kwargs (:issue:`18699`)
11081109
- :func:`DatetimeIndex.to_series` now accepts ``index`` and ``name`` kwargs (:issue:`18699`)
11091110
- Bug in indexing non-scalar value from ``Series`` having non-unique ``Index`` will return value flattened (:issue:`17610`)
1111+
- Bug in indexing with iterator containing only missing keys, which raised no error (:issue:`20748`)
1112+
- Fixed inconsistency in ``.ix`` between list and scalar keys when index has integer dtype and does not include desired key(s) (:issue:`20753`)
11101113
- Bug in ``__setitem__`` when indexing a :class:`DataFrame` with a 2-d boolean ndarray (:issue:`18582`)
11111114
- Bug in ``str.extractall`` when there were no matches empty :class:`Index` was returned instead of appropriate :class:`MultiIndex` (:issue:`19034`)
11121115
- 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

Lines changed: 3 additions & 0 deletions
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)