Skip to content

Slicing an index with DateTime throws AttributeError: 'int' object has no attribute 'stop' #27127

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 9 commits into from
Jul 1, 2019
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Indexing
- Bug in which :meth:`DataFrame.to_csv` caused a segfault for a reindexed data frame, when the indices were single-level :class:`MultiIndex` (:issue:`26303`).
- Fixed bug where assigning a :class:`arrays.PandasArray` to a :class:`pandas.core.frame.DataFrame` would raise error (:issue:`26390`)
- Allow keyword arguments for callable local reference used in the :meth:`DataFrame.query` string (:issue:`26426`)

- Bug which produced ``AttributeError`` on partial matching :class:`Timestamp` in a :class:`MultiIndex` (:issue:`26944`)

Missing
^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2755,7 +2755,9 @@ def convert_indexer(start, stop, step, indexer=indexer,
# a partial date slicer on a DatetimeIndex generates a slice
# note that the stop ALREADY includes the stopped point (if
# it was a string sliced)
return convert_indexer(start.start, stop.stop, step)
start = getattr(start, 'start', start)
stop = getattr(stop, 'stop', stop)
return convert_indexer(start, stop, step)

elif level > 0 or self.lexsort_depth == 0 or step is not None:
# need to have like semantics here to right
Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/indexes/multi/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,24 @@ def test_get_indexer_categorical_time():
Categorical(date_range("2012-01-01", periods=3, freq='H'))])
result = midx.get_indexer(midx)
tm.assert_numpy_array_equal(result, np.arange(9, dtype=np.intp))


def test_timestamp_multiindex_indexer():
# https://github.com/pandas-dev/pandas/issues/26944
idx = pd.MultiIndex.from_product([
pd.date_range("2019-01-01T00:15:33", periods=100, freq="H",
name="date"),
['x'],
[3]
])
df = pd.DataFrame({'foo': np.arange(len(idx))}, idx)
result = df.loc[pd.IndexSlice['2019-1-2':, "x", :], 'foo']
qidx = pd.MultiIndex.from_product([
pd.date_range(start="2019-01-02T00:15:33", end='2019-01-05T02:15:33',
freq="H", name="date"),
['x'],
[3]
])
should_be = pd.Series(data=np.arange(24, len(qidx) + 24), index=qidx,
name="foo")
tm.assert_series_equal(result, should_be)