Skip to content

Commit 25b1224

Browse files
jbrockmendelnickleus27
authored andcommitted
TST: FIXMES in DataFrame.quantile tests (pandas-dev#44437)
1 parent 4f05236 commit 25b1224

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

pandas/tests/frame/methods/test_quantile.py

+37-11
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,13 @@ def test_quantile_datetime(self):
280280
tm.assert_frame_equal(result, expected)
281281

282282
# empty when numeric_only=True
283-
# FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
284-
# result = df[['a', 'c']].quantile(.5)
285-
# result = df[['a', 'c']].quantile([.5])
283+
result = df[["a", "c"]].quantile(0.5)
284+
expected = Series([], index=[], dtype=np.float64, name=0.5)
285+
tm.assert_series_equal(result, expected)
286+
287+
result = df[["a", "c"]].quantile([0.5])
288+
expected = DataFrame(index=[0.5])
289+
tm.assert_frame_equal(result, expected)
286290

287291
def test_quantile_invalid(self, datetime_frame):
288292
msg = "percentiles should all be in the interval \\[0, 1\\]"
@@ -481,7 +485,7 @@ def test_quantile_nat(self):
481485
)
482486
tm.assert_frame_equal(res, exp)
483487

484-
def test_quantile_empty_no_rows(self):
488+
def test_quantile_empty_no_rows_floats(self):
485489

486490
# floats
487491
df = DataFrame(columns=["a", "b"], dtype="float64")
@@ -494,21 +498,43 @@ def test_quantile_empty_no_rows(self):
494498
exp = DataFrame([[np.nan, np.nan]], columns=["a", "b"], index=[0.5])
495499
tm.assert_frame_equal(res, exp)
496500

497-
# FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
498-
# res = df.quantile(0.5, axis=1)
499-
# res = df.quantile([0.5], axis=1)
501+
res = df.quantile(0.5, axis=1)
502+
exp = Series([], index=[], dtype="float64", name=0.5)
503+
tm.assert_series_equal(res, exp)
504+
505+
res = df.quantile([0.5], axis=1)
506+
exp = DataFrame(columns=[], index=[0.5])
507+
tm.assert_frame_equal(res, exp)
500508

509+
def test_quantile_empty_no_rows_ints(self):
501510
# ints
502511
df = DataFrame(columns=["a", "b"], dtype="int64")
503512

504-
# FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
505-
# res = df.quantile(0.5)
513+
res = df.quantile(0.5)
514+
exp = Series([np.nan, np.nan], index=["a", "b"], name=0.5)
515+
tm.assert_series_equal(res, exp)
506516

517+
def test_quantile_empty_no_rows_dt64(self):
507518
# datetimes
508519
df = DataFrame(columns=["a", "b"], dtype="datetime64[ns]")
509520

510-
# FIXME (gives NaNs instead of NaT in 0.18.1 or 0.19.0)
511-
# res = df.quantile(0.5, numeric_only=False)
521+
res = df.quantile(0.5, numeric_only=False)
522+
exp = Series(
523+
[pd.NaT, pd.NaT], index=["a", "b"], dtype="datetime64[ns]", name=0.5
524+
)
525+
tm.assert_series_equal(res, exp)
526+
527+
# Mixed dt64/dt64tz
528+
df["a"] = df["a"].dt.tz_localize("US/Central")
529+
res = df.quantile(0.5, numeric_only=False)
530+
exp = exp.astype(object)
531+
tm.assert_series_equal(res, exp)
532+
533+
# both dt64tz
534+
df["b"] = df["b"].dt.tz_localize("US/Central")
535+
res = df.quantile(0.5, numeric_only=False)
536+
exp = exp.astype(df["b"].dtype)
537+
tm.assert_series_equal(res, exp)
512538

513539
def test_quantile_empty_no_columns(self):
514540
# GH#23925 _get_numeric_data may drop all columns

0 commit comments

Comments
 (0)