You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* upstream/master:
BUG: related to GH5080, get_indexer choking on boolean type promotion (GH8024)
API: consistency in .loc indexing when no values are found in a list-like indexer (GH7999)
Copy file name to clipboardExpand all lines: doc/source/indexing.rst
+1-1
Original file line number
Diff line number
Diff line change
@@ -282,7 +282,7 @@ Selection By Label
282
282
See :ref:`Returning a View versus Copy <indexing.view_versus_copy>`
283
283
284
284
pandas provides a suite of methods in order to have **purely label based indexing**. This is a strict inclusion based protocol.
285
-
**ALL** of the labels for which you ask, must be in the index or a ``KeyError`` will be raised! When slicing, the start bound is *included*, **AND** the stop bound is *included*. Integers are valid labels, but they refer to the label **and not the position**.
285
+
**at least 1** of the labels for which you ask, must be in the index or a ``KeyError`` will be raised! When slicing, the start bound is *included*, **AND** the stop bound is *included*. Integers are valid labels, but they refer to the label **and not the position**.
286
286
287
287
The ``.loc`` attribute is the primary access method. The following are valid inputs:
Copy file name to clipboardExpand all lines: doc/source/v0.15.0.txt
+45-1
Original file line number
Diff line number
Diff line change
@@ -178,6 +178,50 @@ API changes
178
178
as the ``left`` argument. (:issue:`7737`)
179
179
180
180
- Histogram from ``DataFrame.plot`` with ``kind='hist'`` (:issue:`7809`), See :ref:`the docs<visualization.hist>`.
181
+
- Consistency when indexing with ``.loc`` and a list-like indexer when no values are found.
182
+
183
+
.. ipython:: python
184
+
185
+
df = DataFrame([['a'],['b']],index=[1,2])
186
+
df
187
+
188
+
In prior versions there was a difference in these two constructs:
189
+
190
+
- ``df.loc[[3]]`` would (prior to 0.15.0) return a frame reindexed by 3 (with all ``np.nan`` values)
191
+
- ``df.loc[[3],:]`` would raise ``KeyError``.
192
+
193
+
Both will now raise a ``KeyError``. The rule is that *at least 1* indexer must be found when using a list-like and ``.loc`` (:issue:`7999`)
194
+
195
+
There was also a difference between ``df.loc[[1,3]]`` (returns a frame reindexed by ``[1, 3]``) and ``df.loc[[1, 3],:]`` (would raise ``KeyError`` prior to 0.15.0). Both will now return a reindexed frame.
196
+
197
+
.. ipython:: python
198
+
199
+
df.loc[[1,3]]
200
+
df.loc[[1,3],:]
201
+
202
+
This can also be seen in multi-axis indexing with a ``Panel``.
The following would raise ``KeyError`` prior to 0.15.0:
211
+
212
+
.. ipython:: python
213
+
214
+
p.loc[['ItemA','ItemD'],:,'D']
215
+
216
+
Furthermore, ``.loc`` will raise If no values are found in a multi-index with a list-like indexer:
217
+
218
+
.. ipython:: python
219
+
:okexcept:
220
+
221
+
s = Series(np.arange(3,dtype='int64'),index=MultiIndex.from_product([['A'],['foo','bar','baz']],
222
+
names=['one','two'])).sortlevel()
223
+
s
224
+
s.loc[['D']]
181
225
182
226
.. _whatsnew_0150.dt:
183
227
@@ -217,7 +261,7 @@ Internal Refactoring
217
261
218
262
In 0.15.0 ``Index`` has internally been refactored to no longer sub-class ``ndarray``
219
263
but instead subclass ``PandasObject``, similarly to the rest of the pandas objects. This change allows very easy sub-classing and creation of new index types. This should be
220
-
a transparent change with only very limited API implications (:issue:`5080`, :issue:`7439`, :issue:`7796`)
264
+
a transparent change with only very limited API implications (:issue:`5080`, :issue:`7439`, :issue:`7796`, :issue:`8024`)
221
265
222
266
- you may need to unpickle pandas version < 0.15.0 pickles using ``pd.read_pickle`` rather than ``pickle.load``. See :ref:`pickle docs <io.pickle>`
223
267
- when plotting with a ``PeriodIndex``. The ``matplotlib`` internal axes will now be arrays of ``Period`` rather than a ``PeriodIndex``. (this is similar to how a ``DatetimeIndex`` passes arrays of ``datetimes`` now)
0 commit comments