def assert_series_equal(cls, left, right, *args, **kwargs): if left.dtype.name == "json": assert left.dtype == right.dtype left = pd.Series(JSONArray(left.values.astype(object)), index=left.index, name=left.name) right = pd.Series( JSONArray(right.values.astype(object)), index=right.index, name=right.name, ) tm.assert_series_equal(left, right, *args, **kwargs)
def data_for_grouping(): return JSONArray([ { "b": 1 }, { "b": 1 }, {}, {}, { "a": 0, "c": 2 }, { "a": 0, "c": 2 }, { "b": 1 }, { "c": 2 }, ])
def test_custom_asserts(self): # This would always trigger the KeyError from trying to put # an array of equal-length UserDicts inside an ndarray. data = JSONArray([ collections.UserDict({"a": 1}), collections.UserDict({"b": 2}), collections.UserDict({"c": 3}), ]) a = pd.Series(data) self.assert_series_equal(a, a) self.assert_frame_equal(a.to_frame(), a.to_frame()) b = pd.Series(data.take([0, 0, 1])) msg = r"ExtensionArray are different" with pytest.raises(AssertionError, match=msg): self.assert_series_equal(a, b) with pytest.raises(AssertionError, match=msg): self.assert_frame_equal(a.to_frame(), b.to_frame())
def data(): """Length-100 PeriodArray for semantics test.""" data = make_data() # Why the while loop? NumPy is unable to construct an ndarray from # equal-length ndarrays. Many of our operations involve coercing the # EA to an ndarray of objects. To avoid random test failures, we ensure # that our data is coercible to an ndarray. Several tests deal with only # the first two elements, so that's what we'll check. while len(data[0]) == len(data[1]): data = make_data() return JSONArray(data)
def data_missing_for_sorting(): return JSONArray([{"b": 1}, {}, {"a": 4}])
def data_for_sorting(): return JSONArray([{"b": 1}, {"c": 4}, {"a": 2, "c": 3}])
def data_missing(): """Length 2 array with [NA, Valid]""" return JSONArray([{}, {"a": 10}])