Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: FIXMES in DataFrame.quantile tests #44437

Merged
merged 2 commits into from
Nov 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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