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)
评论列表
文章目录