Skip to content

Commit 81fc594

Browse files
rhshadrachfeefladder
authored andcommitted
CI: Fix doctests (pandas-dev#42790)
1 parent 36f2fa6 commit 81fc594

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

pandas/core/construction.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ def extract_array(
405405
For an ndarray-backed Series / Index a PandasArray is returned.
406406
407407
>>> extract_array(pd.Series([1, 2, 3]))
408-
<PandasArray>
409-
[1, 2, 3]
410-
Length: 3, dtype: int64
408+
array([1, 2, 3])
411409
412410
To extract all the way down to the ndarray, pass ``extract_numpy=True``.
413411

pandas/core/indexes/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -5406,6 +5406,9 @@ def _get_indexer_strict(self, key, axis_name: str_t) -> tuple[Index, np.ndarray]
54065406
self._raise_if_missing(keyarr, indexer, axis_name)
54075407

54085408
keyarr = self.take(indexer)
5409+
if isinstance(key, Index):
5410+
# GH 42790 - Preserve name from an Index
5411+
keyarr.name = key.name
54095412
if keyarr.dtype.kind in ["m", "M"]:
54105413
# DTI/TDI.take can infer a freq in some cases when we dont want one
54115414
if isinstance(key, list) or (

pandas/tests/indexing/test_loc.py

+12
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,18 @@ def test_loc_getitem_listlike_of_datetimelike_keys(self, to_period):
24322432
with pytest.raises(KeyError, match="not in index"):
24332433
ser.loc[keys]
24342434

2435+
def test_loc_named_index(self):
2436+
# GH 42790
2437+
df = DataFrame(
2438+
[[1, 2], [4, 5], [7, 8]],
2439+
index=["cobra", "viper", "sidewinder"],
2440+
columns=["max_speed", "shield"],
2441+
)
2442+
expected = df.iloc[:2]
2443+
expected.index.name = "foo"
2444+
result = df.loc[Index(["cobra", "viper"], name="foo")]
2445+
tm.assert_frame_equal(result, expected)
2446+
24352447

24362448
@pytest.mark.parametrize(
24372449
"columns, column_key, expected_columns",

0 commit comments

Comments
 (0)