Skip to content

REGR: Regression in datetimelike slice indexing with a duplicated index and non-exact end-points (GH7523) #7525

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 20, 2014
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
1 change: 1 addition & 0 deletions doc/source/v0.14.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Bug Fixes
~~~~~~~~~
- Bug in ``DataFrame.where`` with a symmetric shaped frame and a passed other of a DataFrame (:issue:`7506`)
- Bug in Panel indexing with a multi-index axis (:issue:`7516`)
- Regression in datetimelike slice indexing with a duplicated index and non-exact end-points (:issue:`7523`)

- Bug in timeops with non-aligned Series (:issue:`7500`)

Expand Down
6 changes: 5 additions & 1 deletion pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,11 @@ def _get_slice(starting_value, offset, search_side, slice_property,

except KeyError:
if self.is_monotonic:
if not is_unique:

# we are duplicated but non-unique
# so if we have an indexer then we are done
# else search for it (GH 7523)
if not is_unique and is_integer(search_value):
slc = search_value
else:
slc = self.searchsorted(search_value,
Expand Down
38 changes: 37 additions & 1 deletion pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2966,6 +2966,42 @@ def test_slice_locs_indexerror(self):
s = Series(lrange(100000), times)
s.ix[datetime(1900, 1, 1):datetime(2100, 1, 1)]

def test_slicing_datetimes(self):

# GH 7523

# unique
df = DataFrame(np.arange(4.,dtype='float64'),
index=[datetime(2001, 1, i, 10, 00) for i in [1,2,3,4]])
result = df.ix[datetime(2001,1,1,10):]
assert_frame_equal(result,df)
result = df.ix[:datetime(2001,1,4,10)]
assert_frame_equal(result,df)
result = df.ix[datetime(2001,1,1,10):datetime(2001,1,4,10)]
assert_frame_equal(result,df)

result = df.ix[datetime(2001,1,1,11):]
expected = df.iloc[1:]
assert_frame_equal(result,expected)
result = df.ix['20010101 11':]
assert_frame_equal(result,expected)

# duplicates
df = pd.DataFrame(np.arange(5.,dtype='float64'),
index=[datetime(2001, 1, i, 10, 00) for i in [1,2,2,3,4]])

result = df.ix[datetime(2001,1,1,10):]
assert_frame_equal(result,df)
result = df.ix[:datetime(2001,1,4,10)]
assert_frame_equal(result,df)
result = df.ix[datetime(2001,1,1,10):datetime(2001,1,4,10)]
assert_frame_equal(result,df)

result = df.ix[datetime(2001,1,1,11):]
expected = df.iloc[1:]
assert_frame_equal(result,expected)
result = df.ix['20010101 11':]
assert_frame_equal(result,expected)

class TestSeriesDatetime64(tm.TestCase):

Expand Down Expand Up @@ -3054,7 +3090,7 @@ def test_intersection(self):
for tz in [None, 'Asia/Tokyo']:
rng = date_range('6/1/2000', '6/30/2000', freq='D', name='idx')

# if target has the same name, it is preserved
# if target has the same name, it is preserved
rng2 = date_range('5/15/2000', '6/20/2000', freq='D', name='idx')
expected2 = date_range('6/1/2000', '6/20/2000', freq='D', name='idx')

Expand Down