Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Jun 17, 2024
1 parent 67cf96b commit eff7c46
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Timezones
Numeric
^^^^^^^
- Bug in ``np.matmul`` with :class:`Index` inputs raising a ``TypeError`` (:issue:`57079`)
-
- Bug in :meth:`DataFrame.quantile` where the column type was not preserved when ``numeric_only=True`` with a list-like ``q`` produced an empty result (:issue:`?``)

Conversion
^^^^^^^^^^
Expand Down
8 changes: 3 additions & 5 deletions pandas/core/methods/selectn.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
)
from pandas.core.dtypes.dtypes import BaseMaskedDtype

from pandas.core.indexes.api import default_index

if TYPE_CHECKING:
from pandas._typing import (
DtypeObj,
Expand All @@ -38,6 +40,7 @@

from pandas import (
DataFrame,
Index,
Series,
)
else:
Expand Down Expand Up @@ -199,11 +202,6 @@ def __init__(self, obj: DataFrame, n: int, keep: str, columns: IndexLabel) -> No
self.columns = columns

def compute(self, method: str) -> DataFrame:
from pandas.core.api import (
Index,
default_index,
)

n = self.n
frame = self.obj
columns = self.columns
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,14 @@ def test_quantile_empty_no_columns(self, interp_method):
result = df.quantile(
0.5, numeric_only=True, interpolation=interpolation, method=method
)
expected = Series([], index=[], name=0.5, dtype=np.float64)
expected = Series([], name=0.5, dtype=np.float64)
expected.index.name = "captain tightpants"
tm.assert_series_equal(result, expected)

result = df.quantile(
[0.5], numeric_only=True, interpolation=interpolation, method=method
)
expected = DataFrame([], index=[0.5], columns=[])
expected = DataFrame([], index=[0.5])
expected.columns.name = "captain tightpants"
tm.assert_frame_equal(result, expected)

Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ def test_get_numeric_data(self, frame_or_series):
if isinstance(o, DataFrame):
# preserve columns dtype
expected.columns = o.columns[:0]
# https://github.com/pandas-dev/pandas/issues/50862
tm.assert_equal(result.reset_index(drop=True), expected)
tm.assert_equal(result, expected)

# get the bool data
arr = np.array([True, True, False, True])
o = construct(frame_or_series, n, value=arr, **kwargs)
result = o._get_numeric_data()
tm.assert_equal(result, o)

def test_get_bool_data_empty_preserve_index(self):
expected = Series([], dtype="bool")
result = expected._get_bool_data()
tm.assert_series_equal(result, expected, check_index_type=True)

def test_nonzero(self, frame_or_series):
# GH 4633
# look at the boolean/nonzero behavior for objects
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ def test_ensure_index_uint64(self):

def test_get_combined_index(self):
result = _get_combined_index([])
expected = Index([])
expected = RangeIndex(0)
tm.assert_index_equal(result, expected)


Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/series/methods/test_get_numeric_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pandas import (
Index,
Series,
date_range,
)
Expand All @@ -19,7 +18,7 @@ def test_get_numeric_data_preserve_dtype(self):

obj = Series([1, "2", 3.0])
result = obj._get_numeric_data()
expected = Series([], dtype=object, index=Index([], dtype=object))
expected = Series([], dtype=object)
tm.assert_series_equal(result, expected)

obj = Series([True, False, True])
Expand All @@ -28,5 +27,5 @@ def test_get_numeric_data_preserve_dtype(self):

obj = Series(date_range("20130101", periods=3))
result = obj._get_numeric_data()
expected = Series([], dtype="M8[ns]", index=Index([], dtype=object))
expected = Series([], dtype="M8[ns]")
tm.assert_series_equal(result, expected)

0 comments on commit eff7c46

Please sign in to comment.