Skip to content

Commit

Permalink
TST: FIXMES in DataFrame.quantile tests (pandas-dev#44437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and nickleus27 committed Nov 28, 2021
1 parent 4f05236 commit 25b1224
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions pandas/tests/frame/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,13 @@ def test_quantile_datetime(self):
tm.assert_frame_equal(result, expected)

# empty when numeric_only=True
# FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
# result = df[['a', 'c']].quantile(.5)
# result = df[['a', 'c']].quantile([.5])
result = df[["a", "c"]].quantile(0.5)
expected = Series([], index=[], dtype=np.float64, name=0.5)
tm.assert_series_equal(result, expected)

result = df[["a", "c"]].quantile([0.5])
expected = DataFrame(index=[0.5])
tm.assert_frame_equal(result, expected)

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

def test_quantile_empty_no_rows(self):
def test_quantile_empty_no_rows_floats(self):

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

# FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
# res = df.quantile(0.5, axis=1)
# res = df.quantile([0.5], axis=1)
res = df.quantile(0.5, axis=1)
exp = Series([], index=[], dtype="float64", name=0.5)
tm.assert_series_equal(res, exp)

res = df.quantile([0.5], axis=1)
exp = DataFrame(columns=[], index=[0.5])
tm.assert_frame_equal(res, exp)

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

# FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
# res = df.quantile(0.5)
res = df.quantile(0.5)
exp = Series([np.nan, np.nan], index=["a", "b"], name=0.5)
tm.assert_series_equal(res, exp)

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

# FIXME (gives NaNs instead of NaT in 0.18.1 or 0.19.0)
# res = df.quantile(0.5, numeric_only=False)
res = df.quantile(0.5, numeric_only=False)
exp = Series(
[pd.NaT, pd.NaT], index=["a", "b"], dtype="datetime64[ns]", name=0.5
)
tm.assert_series_equal(res, exp)

# Mixed dt64/dt64tz
df["a"] = df["a"].dt.tz_localize("US/Central")
res = df.quantile(0.5, numeric_only=False)
exp = exp.astype(object)
tm.assert_series_equal(res, exp)

# both dt64tz
df["b"] = df["b"].dt.tz_localize("US/Central")
res = df.quantile(0.5, numeric_only=False)
exp = exp.astype(df["b"].dtype)
tm.assert_series_equal(res, exp)

def test_quantile_empty_no_columns(self):
# GH#23925 _get_numeric_data may drop all columns
Expand Down

0 comments on commit 25b1224

Please sign in to comment.