Skip to content

Commit b43d513

Browse files
author
TomAugspurger
committed
BUG: quantile ignores axis kwarg
1 parent 19c29ec commit b43d513

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

doc/source/v0.14.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,4 @@ Bug Fixes
111111
- Bug in ``CustomBusinessDay.apply`` raiases ``NameError`` when ``np.datetime64`` object is passed (:issue:`7196`)
112112
- Bug in ``MultiIndex.append``, ``concat`` and ``pivot_table`` don't preserve timezone (:issue:`6606`)
113113
- Bug all ``StringMethods`` now work on empty Series (:issue:`7242`)
114+
- Bug in ``quantile`` ignoring the axis keyword argument (:issue`7306`)

pandas/core/frame.py

+2
Original file line numberDiff line numberDiff line change
@@ -4181,6 +4181,8 @@ def f(arr, per):
41814181
return _quantile(values, per)
41824182

41834183
data = self._get_numeric_data() if numeric_only else self
4184+
if axis == 1:
4185+
data = data.T
41844186

41854187
# need to know which cols are timestamp going in so that we can
41864188
# map timestamp over them after getting the quantile.

pandas/tests/test_frame.py

+34
Original file line numberDiff line numberDiff line change
@@ -11103,6 +11103,26 @@ def test_quantile(self):
1110311103
xp = df.median()
1110411104
assert_series_equal(rs, xp)
1110511105

11106+
# axis
11107+
df = DataFrame({"A": [1, 2, 3], "B": [2, 3, 4]}, index=[1, 2, 3])
11108+
result = df.quantile(.5, axis=1)
11109+
expected = Series([1.5, 2.5, 3.5], index=[1, 2, 3])
11110+
assert_series_equal(result, expected)
11111+
11112+
result = df.quantile([.5, .75], axis=1)
11113+
expected = DataFrame({1: [1.5, 1.75], 2: [2.5, 2.75],
11114+
3: [3.5, 3.75]}, index=["0.5", "0.75"])
11115+
assert_frame_equal(result, expected)
11116+
11117+
# We may want to break API in the future to change this
11118+
# so that we exclude non-numeric along the same axis
11119+
# See GH #7312
11120+
df = DataFrame([[1, 2, 3],
11121+
['a', 'b', 4]])
11122+
result = df.quantile(.5, axis=1)
11123+
expected = Series([3., 4.], index=[0, 1])
11124+
assert_series_equal(result, expected)
11125+
1110611126
def test_quantile_multi(self):
1110711127
df = DataFrame([[1, 1, 1], [2, 2, 2], [3, 3, 3]],
1110811128
columns=['a', 'b', 'c'])
@@ -11141,6 +11161,20 @@ def test_quantile_datetime(self):
1114111161
index=[.5], columns=['a', 'b'])
1114211162
assert_frame_equal(result, expected)
1114311163

11164+
# axis = 1
11165+
df['c'] = pd.to_datetime(['2011', '2012'])
11166+
result = df[['a', 'c']].quantile(.5, axis=1, numeric_only=False)
11167+
expected = Series([Timestamp('2010-07-02 12:00:00'),
11168+
Timestamp('2011-07-02 12:00:00')],
11169+
index=[0, 1])
11170+
assert_series_equal(result, expected)
11171+
11172+
result = df[['a', 'c']].quantile([.5], axis=1, numeric_only=False)
11173+
expected = DataFrame([[Timestamp('2010-07-02 12:00:00'),
11174+
Timestamp('2011-07-02 12:00:00')]],
11175+
index=[0.5], columns=[0, 1])
11176+
assert_frame_equal(result, expected)
11177+
1114411178
def test_cumsum(self):
1114511179
self.tsframe.ix[5:10, 0] = nan
1114611180
self.tsframe.ix[10:15, 1] = nan

0 commit comments

Comments
 (0)