Skip to content

BUG: (GH3925) partial string selection with seconds resolution #3931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pandas 0.11.1
in the ``to_replace`` argument wasn't working (GH3907_)
- Fixed ``__truediv__`` in Python 2.7 with ``numexpr`` installed to actually do true division when dividing
two integer arrays with at least 10000 cells total (GH3764_)
- Indexing with a string with seconds resolution not selecting from a time index (GH3925_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand Down Expand Up @@ -355,9 +356,13 @@ pandas 0.11.1
.. _GH3907: https://github.com/pydata/pandas/issues/3907
.. _GH3911: https://github.com/pydata/pandas/issues/3911
.. _GH3912: https://github.com/pydata/pandas/issues/3912
<<<<<<< HEAD
.. _GH3764: https://github.com/pydata/pandas/issues/3764
.. _GH3888: https://github.com/pydata/pandas/issues/3888

=======
.. _GH3925: https://github.com/pydata/pandas/issues/3925
>>>>>>> BUG: (GH3925) Indexing with a string with seconds resolution not selecting from a time index

pandas 0.11.0
=============
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=W0223

from datetime import datetime
from pandas.core.common import _asarray_tuplesafe
from pandas.core.index import Index, MultiIndex, _ensure_index
import pandas.core.common as com
Expand Down
14 changes: 14 additions & 0 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,13 @@ def _partial_date_slice(self, reso, parsed, use_lhs=True, use_rhs=True):
t1 = Timestamp(st, tz=self.tz)
t2 = Timestamp(Timestamp(st + offsets.Minute(),
tz=self.tz).value - 1)
elif (reso == 'second' and (
self._resolution == Resolution.RESO_SEC or not is_monotonic)):
st = datetime(parsed.year, parsed.month, parsed.day,
hour=parsed.hour, minute=parsed.minute, second=parsed.second)
t1 = Timestamp(st, tz=self.tz)
t2 = Timestamp(Timestamp(st + offsets.Second(),
tz=self.tz).value - 1)
else:
raise KeyError

Expand All @@ -1110,9 +1117,16 @@ def _partial_date_slice(self, reso, parsed, use_lhs=True, use_rhs=True):

if is_monotonic:

# we are out of range
if len(stamps) and (
(use_lhs and t1.value < stamps[0] and t2.value < stamps[0]) or (
(use_rhs and t1.value > stamps[-1] and t2.value > stamps[-1]))):
raise KeyError

# a monotonic (sorted) series can be sliced
left = stamps.searchsorted(t1.value, side='left') if use_lhs else None
right = stamps.searchsorted(t2.value, side='right') if use_rhs else None

return slice(left, right)

lhs_mask = (stamps>=t1.value) if use_lhs else True
Expand Down
9 changes: 9 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ def test_indexing(self):
expected = ts['2013']
assert_series_equal(expected,ts)

# GH 3925, indexing with a seconds resolution string / datetime object
df = DataFrame(randn(5,5),columns=['open','high','low','close','volume'],index=date_range('2012-01-02 18:01:00',periods=5,tz='US/Central',freq='s'))
expected = df.loc[[df.index[2]]]
result = df['2012-01-02 18:01:02']
self.assert_(result == expected)

# this is a single date, so will raise
self.assertRaises(KeyError, df.__getitem__, df.index[2],)

def assert_range_equal(left, right):
assert(left.equals(right))
assert(left.freq == right.freq)
Expand Down