def test_var(): out = df.i32.reshape((2, 2, 5)).var(axis=2).T eq(c.points(df, 'x', 'y', ds.var('i32')), out) eq(c.points(df, 'x', 'y', ds.var('i64')), out) out = np.nanvar(df.f64.reshape((2, 2, 5)), axis=2).T eq(c.points(df, 'x', 'y', ds.var('f32')), out) eq(c.points(df, 'x', 'y', ds.var('f64')), out)
def test_var(): out = xr.DataArray(df.i32.values.reshape((2, 2, 5)).var(axis=2, dtype='f8').T, coords=coords, dims=dims) assert_eq(c.points(ddf, 'x', 'y', ds.var('i32')), out) assert_eq(c.points(ddf, 'x', 'y', ds.var('i64')), out) out = xr.DataArray(np.nanvar(df.f64.values.reshape((2, 2, 5)), axis=2).T, coords=coords, dims=dims) assert_eq(c.points(ddf, 'x', 'y', ds.var('f32')), out) assert_eq(c.points(ddf, 'x', 'y', ds.var('f64')), out)
def test_var(): out = xr.DataArray(df.i32.values.reshape((2, 2, 5)).var(axis=2, dtype='f8').T, coords=coords, dims=dims) assert_eq(c.points(df, 'x', 'y', ds.var('i32')), out) assert_eq(c.points(df, 'x', 'y', ds.var('i64')), out) out = xr.DataArray(np.nanvar(df.f64.values.reshape((2, 2, 5)), axis=2).T, coords=coords, dims=dims) assert_eq(c.points(df, 'x', 'y', ds.var('f32')), out) assert_eq(c.points(df, 'x', 'y', ds.var('f64')), out)
def test_var(ddf): if dask_cudf and isinstance(ddf, dask_cudf.DataFrame): pytest.skip("var not supported with cudf") out = xr.DataArray( values(df_pd.i32).reshape((2, 2, 5)).var(axis=2, dtype='f8').T, coords=coords, dims=dims) assert_eq_xr(c.points(ddf, 'x', 'y', ds.var('i32')), out) assert_eq_xr(c.points(ddf, 'x', 'y', ds.var('i64')), out) out = xr.DataArray( np.nanvar(values(df_pd.f64).reshape((2, 2, 5)), axis=2).T, coords=coords, dims=dims) assert_eq_xr(c.points(ddf, 'x', 'y', ds.var('f32')), out) assert_eq_xr(c.points(ddf, 'x', 'y', ds.var('f64')), out)
def test_categorical_var(ddf): sol = np.array([[[ 2.5, nan, nan, nan], [ nan, nan, 2., nan]], [[ nan, 2., nan, nan], [ nan, nan, nan, 2.]]]) out = xr.DataArray( sol, coords=(coords + [['a', 'b', 'c', 'd']]), dims=(dims + ['cat'])) agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.var('f32'))) assert_eq_xr(agg, out, True) agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.var('f64'))) assert_eq_xr(agg, out, True)
def test_categorical_var(ddf): if cudf and isinstance(ddf._meta, cudf.DataFrame): pytest.skip("The 'var' reduction is yet supported on the GPU") sol = np.array([[[2.5, nan, nan, nan], [nan, nan, 2., nan]], [[nan, 2., nan, nan], [nan, nan, nan, 2.]]]) out = xr.DataArray(sol, coords=(coords + [['a', 'b', 'c', 'd']]), dims=(dims + ['cat'])) agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.var('f32'))) assert_eq_xr(agg, out, True) agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.var('f64'))) assert_eq_xr(agg, out, True)
def test_categorical_var(ddf): if cudf and isinstance(ddf._meta, cudf.DataFrame): pytest.skip("The 'var' reduction is yet supported on the GPU") sol = np.array([[[2.5, nan, nan, nan], [nan, nan, 2., nan]], [[nan, 2., nan, nan], [nan, nan, nan, 2.]]]) out = xr.DataArray(sol, coords=(coords + [['a', 'b', 'c', 'd']]), dims=(dims + ['cat'])) agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.var('f32'))) assert_eq_xr(agg, out, True) agg = c.points(ddf, 'x', 'y', ds.by('cat', ds.var('f64'))) assert_eq_xr(agg, out, True) out = xr.DataArray(sol, coords=(coords + [range(4)]), dims=(dims + ['cat_int'])) agg = c.points( ddf, 'x', 'y', ds.by(ds.category_modulo('cat_int', modulo=4, offset=10), ds.var('f32'))) assert_eq_xr(agg, out) agg = c.points( ddf, 'x', 'y', ds.by(ds.category_modulo('cat_int', modulo=4, offset=10), ds.var('f64'))) assert_eq_xr(agg, out) # add an extra category (this will count nans and out of bounds) sol = np.append(sol, [[[nan], [nan]], [[nan], [nan]]], axis=2) for col in 'f32', 'f64': out = xr.DataArray(sol, coords=(coords + [range(5)]), dims=(dims + [col])) agg = c.points(ddf, 'x', 'y', ds.by(ds.category_binning(col, 0, 20, 4), ds.var(col))) assert_eq_xr(agg, out)
def test_var(): out = df.i32.reshape((2, 2, 5)).var(axis=2).T eq(c.points(ddf, 'x', 'y', agg=ds.var('i32')).agg, out) eq(c.points(ddf, 'x', 'y', agg=ds.var('i64')).agg, out) eq(c.points(ddf, 'x', 'y', agg=ds.var('f32')).agg, out) eq(c.points(ddf, 'x', 'y', agg=ds.var('f64')).agg, out)