Skip to content
5 changes: 3 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,11 @@ def _get_values_tuple(self, key):
def _get_values(self, indexer):
try:
return self._constructor(self._mgr.get_slice(indexer)).__finalize__(self)
except ValueError:
except (ValueError, AssertionError):
# mpl compat if we look up e.g. ser[:, np.newaxis];
# see tests.series.timeseries.test_mpl_compat_hack
return self._values[indexer]
# the asarray is needed to avoid returning a 2D DatetimeArray
return np.asarray(self._values[indexer])

def _get_value(self, label, takeable: bool = False):
"""
Expand Down
15 changes: 12 additions & 3 deletions pandas/tests/series/indexing/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,19 @@ def test_getitem_generator(string_series):
tm.assert_series_equal(result2, expected)


def test_getitem_ndim_deprecated():
s = Series([0, 1])
@pytest.mark.parametrize(
"series",
[
Series([0, 1]),
Series(date_range("2012-01-01", periods=2)),
Series(date_range("2012-01-01", periods=2, tz="CET")),
],
)
def test_getitem_ndim_deprecated(series):
with tm.assert_produces_warning(FutureWarning):
s[:, None]
res = series[:, None]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob worth testing the actual message (can pass to assert_produces_warning to prevent regressions.


assert isinstance(res, np.ndarray)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you assert the result arrays (parameterize if needed)



def test_getitem_multilevel_scalar_slice_not_implemented(
Expand Down