Skip to content

Commit f151dba

Browse files
committed
add note and fix styling
1 parent 22a6b37 commit f151dba

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ These improvements also fixed certain bugs in groupby:
122122
- :meth:`.DataFrameGroupBy.sum` would have incorrect values when there are multiple groupings, unobserved groups, and non-numeric data (:issue:`43891`)
123123
- :meth:`.DataFrameGroupBy.value_counts` would produce incorrect results when used with some categorical and some non-categorical groupings and ``observed=False`` (:issue:`56016`)
124124

125+
.. _whatsnew_300.notable_bug_fixes.xs_function_default_level:
126+
127+
`DataFrame.xs()` did not work as expected when level was not specified by default. (:issue:`59098`)
128+
129+
ex.
130+
.. ipython:: python
131+
132+
df = pd.DataFrame(dict(i=[1,2,3], j=[1,1,2], x=[10, 100, 1000])).set_index(["i", "j"])
133+
134+
key = (1, 1)
135+
136+
# Returns DataFrame as expected:
137+
result1 = df.xs(key, drop_level=False, level=list(range(len(key))))
138+
139+
# Returns Series, but DataFrame was expected:
140+
result2 = df.xs(key, drop_level=False)
141+
142+
125143
.. _whatsnew_300.notable_bug_fixes.notable_bug_fix2:
126144

127145
notable_bug_fix2

pandas/tests/series/indexing/test_xs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22
import pytest
3-
import debugpy
43

54
from pandas import (
65
DataFrame,
@@ -82,7 +81,7 @@ def test_xs_key_as_list(self):
8281

8382
with pytest.raises(TypeError, match="list keys are not supported"):
8483
ser.xs(["a"], axis=0, drop_level=False)
85-
84+
8685
def test_xs_default_level(self):
8786
# GH#59098
8887
df = DataFrame(dict(i=[1,2,3], j=[1,1,2], x=[10, 100, 1000])).set_index(["i", "j"])

0 commit comments

Comments
 (0)