test_reshape.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:xarray_filters 作者: ContinuumIO 项目源码 文件源码
def test_from_features_dropped_rows(X):
    features = X.to_features()
    data1 = features.from_features()

    # Assert that we get the original Dataset back after X.to_features().from_features()
    assert np.array_equal(data1.coords.to_index().values, X.coords.to_index().values)
    assert np.allclose(data1.to_xy_arrays()[0], X.to_xy_arrays()[0])

    # Drop some rows
    features['features'].values[:2, :] = np.nan
    zerod_vals_copy = features['features'].values[:] # Copy NaN positions for testing later on
    features = features.dropna(features['features'].dims[0])

    # Convert back to original dataset, padding NaN values into the proper locations if necessary
    data2 = features.from_features()

    # Assert that the coords are correct, and NaNs are in the right places
    if np.nan in data2.to_xy_arrays()[0]:
        assert np.array_equal(data2.coords.to_index().values, data1.coords.to_index().values)
        assert np.allclose(data2.to_xy_arrays()[0], zerod_vals_copy, equal_nan=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号