ContinuumIO / xarray_filters

A Pipeline approach to chaining common xarray data structure conversions
3 stars 10 forks source link

MLDataset.*_features() should be idempotent #38

Closed gbrener closed 6 years ago

gbrener commented 7 years ago

The mlds.to_features() and mlds.from_features() methods should be idempotent. Here is an example where this breaks, currently:

import pandas as pd
import numpy as np
import xarray as xr
from xarray_filters import from_features, to_features, MLDataset

index = pd.MultiIndex.from_product((np.arange(2), np.arange(2, 4)), names=('x', 'y'))
arr1 = xr.DataArray(np.random.uniform(0,1, (4, 1)), coords=[('space', index), ('layer', ['pressure'])], dims=('space', 'layer'), name='features')
dset1 = from_features(arr1)
dset2 = dset1.to_features()
dset2.to_features() # fails here

Traceback:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    dset2.to_features()
...
ValueError: conflicting MultiIndex level name(s):
'space' (space), (space)
'layer' (space), (layer)
PeterDSteinberg commented 6 years ago

Fixed by #45