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_setitem_nullable_mask(self, data): # GH 31446 # TODO: there is some issue with PandasArray, therefore, # TODO: skip the setitem test for now, and fix it later if data.dtype != PandasDtype("object"): arr = data[:5] expected = data.take([0, 0, 0, 3, 4]) mask = pd.array([True, True, True, False, False]) arr[mask] = data[0] self.assert_extension_array_equal(expected, arr)
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 test_constructor_from_string(): result = PandasDtype.construct_from_string("int64") expected = PandasDtype(np.dtype("int64")) assert result == expected
def dtype(request): return PandasDtype(np.dtype(request.param))
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
def dtype(): return PandasDtype(np.dtype('float'))
def dtype(): return PandasDtype(np.dtype('object'))