Skip to content

TST: added tests for sparse and date range quantiles #35236

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

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Changes from 1 commit
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
39 changes: 33 additions & 6 deletions pandas/tests/frame/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@


class TestDataFrameQuantile:
def test_quantile_sparse(self):
@pytest.mark.parametrize(
"df,expected",
[
[
pd.DataFrame(
{
0: pd.Series(pd.arrays.SparseArray([1, 2])),
1: pd.Series(pd.arrays.SparseArray([3, 4])),
}
),
pd.Series([1.5, 3.5], name=0.5),
],
[
pd.DataFrame(pd.Series([0.0, None, 1.0, 2.0], dtype="Sparse[float]")),
pd.Series([1.0], name=0.5),
],
],
)
def test_quantile_sparse(self, df, expected):
# GH#17198
s = pd.Series(pd.arrays.SparseArray([1, 2]))
s1 = pd.Series(pd.arrays.SparseArray([3, 4]))
df = pd.DataFrame({0: s, 1: s1})
result = df.quantile()
# GH#24600
result = df.quantile(0.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this should work with df.quantile() yes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we test this elsewhere so prob ok here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes df.quantile() works the same. I can change this.


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

def test_quantile(self, datetime_frame):
Expand Down Expand Up @@ -59,6 +74,18 @@ def test_quantile(self, datetime_frame):
expected = Series([3.0, 4.0], index=[0, 1], name=0.5)
tm.assert_series_equal(result, expected)

def test_quantile_date_range(self):
# GH 2460

dti = pd.date_range("2016-01-01", periods=3, tz="US/Pacific")
ser = pd.Series(dti)
df = pd.DataFrame(ser)

result = df.quantile(0.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected is NO values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has no values unless it is run with numeric_only set to false. So it would be result = df.quantile(numeric_only=False) instead of result = df.quantile().

It probably makes more sense to change it and set numeric_only to false correct?

expected = pd.Series([], index=[], name=0.5, dtype=np.float64)

tm.assert_series_equal(result, expected)

def test_quantile_axis_mixed(self):

# mixed on axis=1
Expand Down