@@ -11103,6 +11103,26 @@ def test_quantile(self):
11103
11103
xp = df.median()
11104
11104
assert_series_equal(rs, xp)
11105
11105
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
+
11106
11126
def test_quantile_multi(self):
11107
11127
df = DataFrame([[1, 1, 1], [2, 2, 2], [3, 3, 3]],
11108
11128
columns=['a', 'b', 'c'])
@@ -11141,6 +11161,20 @@ def test_quantile_datetime(self):
11141
11161
index=[.5], columns=['a', 'b'])
11142
11162
assert_frame_equal(result, expected)
11143
11163
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
+
11144
11178
def test_cumsum(self):
11145
11179
self.tsframe.ix[5:10, 0] = nan
11146
11180
self.tsframe.ix[10:15, 1] = nan
0 commit comments