def test_interpolate_dataset(ds): actual = ds.interpolate_na(dim='time') # no missing values in var1 assert actual['var1'].count('time') == actual.dims['time'] # var2 should be the same as it was assert_array_equal(actual['var2'], ds['var2'])
def test_interpolate_dataset(ds): actual = ds.interpolate_na(dim="time") # no missing values in var1 assert actual["var1"].count("time") == actual.dims["time"] # var2 should be the same as it was assert_array_equal(actual["var2"], ds["var2"])
def test_ffill_limit(): da = xr.DataArray( [0, np.nan, np.nan, np.nan, np.nan, 3, 4, 5, np.nan, 6, 7], dims='time') result = da.ffill('time') expected = xr.DataArray([0, 0, 0, 0, 0, 3, 4, 5, 5, 6, 7], dims='time') assert_array_equal(result, expected) result = da.ffill('time', limit=1) expected = xr.DataArray([0, 0, np.nan, np.nan, np.nan, 3, 4, 5, 5, 6, 7], dims='time')
def test_ffill_limit(): da = xr.DataArray( [0, np.nan, np.nan, np.nan, np.nan, 3, 4, 5, np.nan, 6, 7], dims='time') result = da.ffill('time') expected = xr.DataArray([0, 0, 0, 0, 0, 3, 4, 5, 5, 6, 7], dims='time') assert_array_equal(result, expected) result = da.ffill('time', limit=1) expected = xr.DataArray( [0, 0, np.nan, np.nan, np.nan, 3, 4, 5, 5, 6, 7], dims='time')
def test_get_loc(date_type, index): result = index.get_loc('0001') expected = [0, 1] assert_array_equal(result, expected) result = index.get_loc(date_type(1, 2, 1)) expected = 1 assert result == expected result = index.get_loc('0001-02-01') expected = 1 assert result == expected
def test_interpolators_complex_out_of_bounds(): """Ensure complex nans are used for complex data""" xi = np.array([-1, 0, 1, 2, 5], dtype=np.float64) yi = np.exp(1j * xi) x = np.array([-2, 1, 6], dtype=np.float64) expected = np.array( [np.nan + np.nan * 1j, np.exp(1j), np.nan + np.nan * 1j], dtype=yi.dtype ) for method, interpolator in [ ("linear", NumpyInterpolator), ("linear", ScipyInterpolator), ]: f = interpolator(xi, yi, method=method) actual = f(x) assert_array_equal(actual, expected)
def test_rolling_wrapped_bottleneck(self, da, name, center, min_periods) -> None: bn = pytest.importorskip("bottleneck", minversion="1.1") # Test all bottleneck functions rolling_obj = da.rolling(time=7, min_periods=min_periods) func_name = f"move_{name}" actual = getattr(rolling_obj, name)() expected = getattr(bn, func_name)( da.values, window=7, axis=1, min_count=min_periods ) assert_array_equal(actual.values, expected) with pytest.warns(DeprecationWarning, match="Reductions are applied"): getattr(rolling_obj, name)(dim="time") # Test center rolling_obj = da.rolling(time=7, center=center) actual = getattr(rolling_obj, name)()["time"] assert_equal(actual, da["time"])
def test_rolling_wrapped_bottleneck( self, ds, name, center, min_periods, key ) -> None: bn = pytest.importorskip("bottleneck", minversion="1.1") # Test all bottleneck functions rolling_obj = ds.rolling(time=7, min_periods=min_periods) func_name = f"move_{name}" actual = getattr(rolling_obj, name)() if key == "z1": # z1 does not depend on 'Time' axis. Stored as it is. expected = ds[key] elif key == "z2": expected = getattr(bn, func_name)( ds[key].values, window=7, axis=0, min_count=min_periods ) else: raise ValueError assert_array_equal(actual[key].values, expected) # Test center rolling_obj = ds.rolling(time=7, center=center) actual = getattr(rolling_obj, name)()["time"] assert_equal(actual, ds["time"])
def test_cftimeindex_field_accessors(index, field, expected): result = getattr(index, field) assert_array_equal(result, expected)
def test_cftimeindex_days_in_month_accessor(index): result = index.days_in_month expected = [date.daysinmonth for date in index] assert_array_equal(result, expected)
def test_cftimeindex_dayofweek_accessor(index): result = index.dayofweek expected = [date.dayofwk for date in index] assert_array_equal(result, expected)