def assert_series_equal(cls, left, right, *args, **kwargs): # base class tests hard-code expected values with numpy dtypes, # whereas we generally want the corresponding PandasDtype if (isinstance(right, pd.Series) and not isinstance(right.dtype, ExtensionDtype) and isinstance(left.dtype, PandasDtype)): right = right.astype(PandasDtype(right.dtype)) return tm.assert_series_equal(left, right, *args, **kwargs)
def test_fillna_fill_other(self, data_missing): # Same as the parent class test, but with PandasDtype for expected["B"] # instead of equivalent numpy dtype data = data_missing result = pd.DataFrame({"A": data, "B": [np.nan] * len(data)}).fillna({"B": 0.0}) expected = pd.DataFrame({"A": data, "B": [0.0] * len(result)}) expected["B"] = expected["B"].astype(PandasDtype(expected["B"].dtype)) self.assert_frame_equal(result, expected)
def __init__(self, values: np.ndarray | PandasArray, copy: bool = False): if isinstance(values, type(self)): values = values._ndarray if not isinstance(values, np.ndarray): raise ValueError( f"'values' must be a NumPy array, not {type(values).__name__}") if values.ndim == 0: # Technically we support 2, but do not advertise that fact. raise ValueError("PandasArray must be 1-dimensional.") if copy: values = values.copy() dtype = PandasDtype(values.dtype) super().__init__(values, dtype)
def dtype(request): return PandasDtype(np.dtype(request.param))
def test_dtype_univalent(any_numpy_dtype): dtype = PandasDtype(any_numpy_dtype) result = PandasDtype(dtype) assert result == dtype
def test_constructor_from_string(): result = PandasDtype.construct_from_string("int64") expected = PandasDtype(np.dtype("int64")) assert result == expected
def test_repr(): dtype = PandasDtype(np.dtype("int64")) assert repr(dtype) == "PandasDtype('int64')"
def test_is_boolean(dtype, expected): dtype = PandasDtype(dtype) assert dtype._is_boolean is expected
def test_is_numeric(dtype, expected): dtype = PandasDtype(dtype) assert dtype._is_numeric is expected