diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index a58cdc8c93ab7..d43ace99a55f6 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -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 ^^^^^^^ diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index a06d304fb5a22..074ef2934fc68 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -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 diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index 929c080042a45..3acd194b28a05 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -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)