Skip to content

Commit 721684f

Browse files
committed
add test and whatsnew about changes of pd.Series indexing and __getitem__
1 parent 55d4cc3 commit 721684f

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

doc/source/whatsnew/v0.25.0.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,22 @@ Backwards incompatible API changes
3131
Indexing and getitem
3232
^^^^^^^^^^^^^^^^^^^^
3333

34-
Indexing and getitem of pd.dataframe now accept zerodim np.array.
34+
Indexing and getitem of pd.DataFrame now accept zerodim np.array.
3535

3636
.. ipython:: python
3737
df = pd.DataFrame([[1, 2], [3, 4]])[np.array(0)]
3838
df.iloc[np.array(0)]
3939
df.loc[np.array(0)]
4040
df[np.array(0)]
4141
42+
Indexing and getitem of pd.Series now accept zerodim np.array.
43+
44+
.. ipython:: python
45+
sr = pd.Series([1, 2])
46+
sr.iloc[np.array(0)]
47+
sr.loc[np.array(0)]
48+
sr[np.array(0)]
49+
4250
Other API Changes
4351
^^^^^^^^^^^^^^^^^
4452

pandas/tests/indexing/test_iloc.py

+9
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,12 @@ def test_indexing_zero_dim_np_array(self):
686686
# expected series
687687
sr = pd.Series([1, 2], name=0)
688688
tm.assert_series_equal(result, sr)
689+
690+
def test_series_indexing_zero_dim_np_array(self):
691+
# GH24919
692+
sr = Series([1, 2])
693+
694+
# should not raise an error
695+
result = sr.iloc[np.array(0)]
696+
697+
assert result == 1

pandas/tests/indexing/test_loc.py

+9
Original file line numberDiff line numberDiff line change
@@ -776,3 +776,12 @@ def test_indexing_zero_dim_np_array(self):
776776
# expected series
777777
sr = pd.Series([1, 2], name=0)
778778
tm.assert_series_equal(result, sr)
779+
780+
def test_series_indexing_zero_dim_np_array(self):
781+
# GH24924
782+
sr = Series([1, 2])
783+
784+
# should not raise an error
785+
result = sr.loc[np.array(0)]
786+
787+
assert result == 1

pandas/tests/series/indexing/test_indexing.py

+10
Original file line numberDiff line numberDiff line change
@@ -838,3 +838,13 @@ def test_head_tail(test_data):
838838
assert_series_equal(test_data.series.head(0), test_data.series[0:0])
839839
assert_series_equal(test_data.series.tail(), test_data.series[-5:])
840840
assert_series_equal(test_data.series.tail(0), test_data.series[0:0])
841+
842+
843+
def test_getitem_with_zerodim_np_array():
844+
# GH24924
845+
sr = Series([1, 2])
846+
847+
# should not raise an error
848+
result = sr[np.array(0)]
849+
850+
assert result == 1

0 commit comments

Comments
 (0)