Skip to content

Commit eb41429

Browse files
committed
Merge branch 'quantile-axis' of https://github.com/TomAugspurger/pandas into TomAugspurger-quantile-axis
Conflicts: doc/source/v0.14.1.txt
2 parents ae464f8 + b43d513 commit eb41429

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

doc/source/v0.14.1.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,7 @@ Bug Fixes
169169

170170
- Bug in ``DatetimeIndex.insert`` doesn't preserve ``name`` and ``tz`` (:issue:`7299`)
171171
- Bug in ``DatetimeIndex.asobject`` doesn't preserve ``name`` (:issue:`7299`)
172-
173-
174-
175-
176172
- Bug in multi-index slicing with datetimelike ranges (strings and Timestamps), (:issue:`7429`)
177-
178-
179-
180-
181-
182173
- Bug in ``Index.min`` and ``max`` doesn't handle ``nan`` and ``NaT`` properly (:issue:`7261`)
183174
- Bug in ``resample`` where ``fill_method`` was ignored if you passed ``how`` (:issue:`7261`)
184175
- Bug in ``TimeGrouper`` doesn't exclude column specified by ``key`` (:issue:`7227`)
@@ -221,4 +212,18 @@ Bug Fixes
221212
:issue:`7409`).
222213
- Bug where bool objects were converted to ``nan`` in ``convert_objects``
223214
(:issue:`7416`).
215+
- Bug in ``quantile`` ignoring the axis keyword argument (:issue`7306`)
216+
217+
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
224229

pandas/core/frame.py

Lines changed: 2 additions & 0 deletions
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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11166,6 +11166,26 @@ def test_quantile(self):
1116611166
xp = df.median()
1116711167
assert_series_equal(rs, xp)
1116811168

11169+
# axis
11170+
df = DataFrame({"A": [1, 2, 3], "B": [2, 3, 4]}, index=[1, 2, 3])
11171+
result = df.quantile(.5, axis=1)
11172+
expected = Series([1.5, 2.5, 3.5], index=[1, 2, 3])
11173+
assert_series_equal(result, expected)
11174+
11175+
result = df.quantile([.5, .75], axis=1)
11176+
expected = DataFrame({1: [1.5, 1.75], 2: [2.5, 2.75],
11177+
3: [3.5, 3.75]}, index=["0.5", "0.75"])
11178+
assert_frame_equal(result, expected)
11179+
11180+
# We may want to break API in the future to change this
11181+
# so that we exclude non-numeric along the same axis
11182+
# See GH #7312
11183+
df = DataFrame([[1, 2, 3],
11184+
['a', 'b', 4]])
11185+
result = df.quantile(.5, axis=1)
11186+
expected = Series([3., 4.], index=[0, 1])
11187+
assert_series_equal(result, expected)
11188+
1116911189
def test_quantile_multi(self):
1117011190
df = DataFrame([[1, 1, 1], [2, 2, 2], [3, 3, 3]],
1117111191
columns=['a', 'b', 'c'])
@@ -11204,6 +11224,20 @@ def test_quantile_datetime(self):
1120411224
index=[.5], columns=['a', 'b'])
1120511225
assert_frame_equal(result, expected)
1120611226

11227+
# axis = 1
11228+
df['c'] = pd.to_datetime(['2011', '2012'])
11229+
result = df[['a', 'c']].quantile(.5, axis=1, numeric_only=False)
11230+
expected = Series([Timestamp('2010-07-02 12:00:00'),
11231+
Timestamp('2011-07-02 12:00:00')],
11232+
index=[0, 1])
11233+
assert_series_equal(result, expected)
11234+
11235+
result = df[['a', 'c']].quantile([.5], axis=1, numeric_only=False)
11236+
expected = DataFrame([[Timestamp('2010-07-02 12:00:00'),
11237+
Timestamp('2011-07-02 12:00:00')]],
11238+
index=[0.5], columns=[0, 1])
11239+
assert_frame_equal(result, expected)
11240+
1120711241
def test_cumsum(self):
1120811242
self.tsframe.ix[5:10, 0] = nan
1120911243
self.tsframe.ix[10:15, 1] = nan

0 commit comments

Comments
 (0)