Skip to content

Commit e17d210

Browse files
committed
- Whatsnew section added
- Documentation section added
1 parent 67e6bab commit e17d210

File tree

2 files changed

+71
-16
lines changed

2 files changed

+71
-16
lines changed

doc/source/timeseries.rst

+39-16
Original file line numberDiff line numberDiff line change
@@ -457,22 +457,6 @@ We are stopping on the included end-point as it is part of the index
457457
458458
dft['2013-1-15':'2013-1-15 12:30:00']
459459
460-
.. warning::
461-
462-
The following selection will raise a ``KeyError``; otherwise this selection methodology
463-
would be inconsistent with other selection methods in pandas (as this is not a *slice*, nor does it
464-
resolve to one)
465-
466-
.. code-block:: python
467-
468-
dft['2013-1-15 12:30:00']
469-
470-
To select a single row, use ``.loc``
471-
472-
.. ipython:: python
473-
474-
dft.loc['2013-1-15 12:30:00']
475-
476460
.. versionadded:: 0.18.0
477461

478462
DatetimeIndex Partial String Indexing also works on DataFrames with a ``MultiIndex``. For example:
@@ -491,6 +475,45 @@ DatetimeIndex Partial String Indexing also works on DataFrames with a ``MultiInd
491475
dft2 = dft2.swaplevel(0, 1).sort_index()
492476
dft2.loc[idx[:, '2013-01-05'], :]
493477
478+
String Indexing: slice vs. exact match
479+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
480+
481+
The same string used as an indexing parameter can be treated either as slice or as exact match depending on the resolution of an index. If the string is less precise than index, it will be treated as a slice, otherwise as an exact match.
482+
483+
.. ipython:: python
484+
series_minute = pd.Series([1, 2, 3], DatetimeIndex(['2011-12-31 23:59:00',
485+
'2012-01-01 00:00:00',
486+
'2012-01-01 00:01:00']))
487+
series_minute.index.resolution
488+
series_minute['2011-12-31 23'] # returns Series
489+
series_minute['2012-12-31 23:59'] # returns scalar
490+
491+
series_second = pd.Series([1, 2, 3], DatetimeIndex(['2011-12-31 23:59:59',
492+
'2012-01-01 00:00:00',
493+
'2012-01-01 00:00:01']))
494+
series_second.index.resolution
495+
series_second['2012-12-31 23:59'] # now it returns scalar
496+
497+
It also works for ``DataFrame``:
498+
499+
.. ipython:: python
500+
dft_minute = pd.DataFrame(series_minute)
501+
dft_minute['2011-12-31 23']
502+
503+
.. warning::
504+
505+
If a string used in ``DataFrame``'s ``[]`` indexing is treated as an exact match the selection will be column-wise and not row-wise. This is consistent with :ref:`Indexing Basics <indexing.basics>`. For example, the following code will raise ``KeyError`` as there is no column with index ``'2012-12-31 23:59'``:
506+
507+
.. code-block:: python
508+
509+
df_minute['2012-12-31 23:59']
510+
511+
To select a single row, use ``.loc``
512+
513+
.. ipython:: python
514+
515+
df_minute.loc['2012-12-31 23:59']
516+
494517
Datetime Indexing
495518
~~~~~~~~~~~~~~~~~
496519

doc/source/whatsnew/v0.20.0.txt

+32
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,38 @@ Backwards incompatible API changes
7070
Other API Changes
7171
^^^^^^^^^^^^^^^^^
7272

73+
- :ref:`DatetimeIndex Partial String Indexing <timeseries.partialindexing>` now works as exact match provided that string resolution coincides with index resolution (:issue:`14826`).
74+
75+
.. ipython:: python
76+
77+
df = DataFrame({'a': [1, 2, 3]}, DatetimeIndex(['2011-12-31 23:59:59',
78+
'2012-01-01 00:00:00',
79+
'2012-01-01 00:00:01']))
80+
Previous Behavior:
81+
82+
.. code-block:: ipython
83+
84+
In [4]: df['2011-12-31 23:59:59']
85+
Out[4]:
86+
a
87+
2011-12-31 23:59:59 1
88+
89+
In [5]: df['a']['2011-12-31 23:59:59']
90+
Out[5]:
91+
2011-12-31 23:59:59 1
92+
Name: a, dtype: int64
93+
94+
95+
New Behavior:
96+
97+
.. code-block:: ipython
98+
99+
In [4]: df['2011-12-31 23:59:59']
100+
KeyError: '2011-12-31 23:59:59'
101+
102+
In [5]: df['a']['2011-12-31 23:59:59']
103+
Out[5]: 1
104+
73105
.. _whatsnew_0200.deprecations:
74106

75107
Deprecations

0 commit comments

Comments
 (0)