def test_cumprod_masked(): data = [1, 2, None, 4, 5] float_types = ["float32", "float64"] for type_ in float_types: gs = Series(data).astype(type_) ps = pd.Series(data).astype(type_) assert_eq(gs.cumprod(), ps.cumprod()) for type_ in INTEGER_TYPES: gs = Series(data).astype(type_) got = gs.cumprod() expected = pd.Series([1, 2, np.nan, 8, 40], dtype="float64") assert_eq(got, expected)
def test_cumprod_masked(): data = [1, 2, None, 4, 5] float_types = ["float32", "float64"] int_types = ["int8", "int16", "int32", "int64"] for type_ in float_types: gs = Series(data).astype(type_) ps = pd.Series(data).astype(type_) assert_eq(gs.cumprod(), ps.cumprod()) for type_ in int_types: expected = pd.Series([1, 2, -1, 8, 40]).astype("int64") gs = Series(data).astype(type_) assert_eq(gs.cumprod(), expected)
def test_cumprod(dtype, nelem): if dtype == np.int8: # to keep data in range data = gen_rand(dtype, nelem, low=-2, high=2) else: data = gen_rand(dtype, nelem) decimal = 4 if dtype == np.float32 else 6 # series gs = Series(data) ps = pd.Series(data) np.testing.assert_array_almost_equal(gs.cumprod().to_array(), ps.cumprod(), decimal=decimal) # dataframe series (named series) gdf = DataFrame() gdf["a"] = Series(data) pdf = pd.DataFrame() pdf["a"] = pd.Series(data) np.testing.assert_array_almost_equal(gdf.a.cumprod().to_array(), pdf.a.cumprod(), decimal=decimal)