|
4 | 4 | import pandas as pd
|
5 | 5 | from pandas import (
|
6 | 6 | DataFrame,
|
| 7 | + Index, |
7 | 8 | Series,
|
8 | 9 | Timestamp,
|
9 | 10 | )
|
@@ -650,3 +651,68 @@ def test_quantile_ea_scalar(self, index, frame_or_series):
|
650 | 651 | assert result == expected
|
651 | 652 | else:
|
652 | 653 | tm.assert_series_equal(result, expected)
|
| 654 | + |
| 655 | + @pytest.mark.parametrize( |
| 656 | + "dtype, expected_data, expected_index, axis", |
| 657 | + [ |
| 658 | + ["float64", [], [], 1], |
| 659 | + ["int64", [], [], 1], |
| 660 | + ["float64", [np.nan, np.nan], ["a", "b"], 0], |
| 661 | + ["int64", [np.nan, np.nan], ["a", "b"], 0], |
| 662 | + ], |
| 663 | + ) |
| 664 | + def test_empty_numeric(self, dtype, expected_data, expected_index, axis): |
| 665 | + # GH 14564 |
| 666 | + df = DataFrame(columns=["a", "b"], dtype=dtype) |
| 667 | + result = df.quantile(0.5, axis=axis) |
| 668 | + expected = Series( |
| 669 | + expected_data, name=0.5, index=Index(expected_index), dtype="float64" |
| 670 | + ) |
| 671 | + tm.assert_series_equal(result, expected) |
| 672 | + |
| 673 | + @pytest.mark.parametrize( |
| 674 | + "dtype, expected_data, expected_index, axis, expected_dtype", |
| 675 | + [ |
| 676 | + pytest.param( |
| 677 | + "datetime64[ns]", |
| 678 | + [], |
| 679 | + [], |
| 680 | + 1, |
| 681 | + "datetime64[ns]", |
| 682 | + marks=pytest.mark.xfail(reason="#GH 41544"), |
| 683 | + ), |
| 684 | + ["datetime64[ns]", [pd.NaT, pd.NaT], ["a", "b"], 0, "datetime64[ns]"], |
| 685 | + ], |
| 686 | + ) |
| 687 | + def test_empty_datelike( |
| 688 | + self, dtype, expected_data, expected_index, axis, expected_dtype |
| 689 | + ): |
| 690 | + # GH 14564 |
| 691 | + df = DataFrame(columns=["a", "b"], dtype=dtype) |
| 692 | + result = df.quantile(0.5, axis=axis, numeric_only=False) |
| 693 | + expected = Series( |
| 694 | + expected_data, name=0.5, index=Index(expected_index), dtype=expected_dtype |
| 695 | + ) |
| 696 | + tm.assert_series_equal(result, expected) |
| 697 | + |
| 698 | + @pytest.mark.parametrize( |
| 699 | + "expected_data, expected_index, axis", |
| 700 | + [ |
| 701 | + [[np.nan, np.nan], range(2), 1], |
| 702 | + [[], [], 0], |
| 703 | + ], |
| 704 | + ) |
| 705 | + def test_datelike_numeric_only(self, expected_data, expected_index, axis): |
| 706 | + # GH 14564 |
| 707 | + df = DataFrame( |
| 708 | + { |
| 709 | + "a": pd.to_datetime(["2010", "2011"]), |
| 710 | + "b": [0, 5], |
| 711 | + "c": pd.to_datetime(["2011", "2012"]), |
| 712 | + } |
| 713 | + ) |
| 714 | + result = df[["a", "c"]].quantile(0.5, axis=axis) |
| 715 | + expected = Series( |
| 716 | + expected_data, name=0.5, index=Index(expected_index), dtype=np.float64 |
| 717 | + ) |
| 718 | + tm.assert_series_equal(result, expected) |
0 commit comments