Skip to content

Commit ab1e279

Browse files
sanders41fangchenli
authored andcommitted
TST: added tests for sparse and date range quantiles (pandas-dev#35236)
* TST: added tests for sparse and date range quantiles * TST: updating quantile arguments
1 parent 3b2d07a commit ab1e279

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

pandas/tests/frame/methods/test_quantile.py

+34-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,29 @@
77

88

99
class TestDataFrameQuantile:
10-
def test_quantile_sparse(self):
10+
@pytest.mark.parametrize(
11+
"df,expected",
12+
[
13+
[
14+
pd.DataFrame(
15+
{
16+
0: pd.Series(pd.arrays.SparseArray([1, 2])),
17+
1: pd.Series(pd.arrays.SparseArray([3, 4])),
18+
}
19+
),
20+
pd.Series([1.5, 3.5], name=0.5),
21+
],
22+
[
23+
pd.DataFrame(pd.Series([0.0, None, 1.0, 2.0], dtype="Sparse[float]")),
24+
pd.Series([1.0], name=0.5),
25+
],
26+
],
27+
)
28+
def test_quantile_sparse(self, df, expected):
1129
# GH#17198
12-
s = pd.Series(pd.arrays.SparseArray([1, 2]))
13-
s1 = pd.Series(pd.arrays.SparseArray([3, 4]))
14-
df = pd.DataFrame({0: s, 1: s1})
30+
# GH#24600
1531
result = df.quantile()
1632

17-
expected = pd.Series([1.5, 3.5], name=0.5)
1833
tm.assert_series_equal(result, expected)
1934

2035
def test_quantile(self, datetime_frame):
@@ -59,6 +74,20 @@ def test_quantile(self, datetime_frame):
5974
expected = Series([3.0, 4.0], index=[0, 1], name=0.5)
6075
tm.assert_series_equal(result, expected)
6176

77+
def test_quantile_date_range(self):
78+
# GH 2460
79+
80+
dti = pd.date_range("2016-01-01", periods=3, tz="US/Pacific")
81+
ser = pd.Series(dti)
82+
df = pd.DataFrame(ser)
83+
84+
result = df.quantile(numeric_only=False)
85+
expected = pd.Series(
86+
["2016-01-02 00:00:00"], name=0.5, dtype="datetime64[ns, US/Pacific]"
87+
)
88+
89+
tm.assert_series_equal(result, expected)
90+
6291
def test_quantile_axis_mixed(self):
6392

6493
# mixed on axis=1

0 commit comments

Comments
 (0)