This repository has been archived by the owner on Jul 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove inplace from packaging. Currently failing tests. * Remove obsolete inplace argument. * test_reset_index is failing with "KeyError: 'up'", which I think means there's a bug in DataArray.reset_index, because it's supposed to be able to take MultiIndex level names. * Moved some stuff to base. * Remove places where we rewrap DataAssemblies as DataArrays, because reset_index works on DataAssembly since the inplace argument removal changes.
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
from brainio_base.assemblies import DataAssembly, get_levels | ||
from brainio_collection.packaging import write_netcdf | ||
|
||
|
||
def test_write_netcdf(): | ||
assy = DataAssembly( | ||
data=[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]], | ||
coords={ | ||
'up': ("a", ['alpha', 'alpha', 'beta', 'beta', 'beta', 'beta']), | ||
'down': ("a", [1, 1, 1, 1, 2, 2]), | ||
'sideways': ('b', ['x', 'y', 'z']) | ||
}, | ||
dims=['a', 'b'] | ||
) | ||
netcdf_path = Path("test.nc") | ||
netcdf_sha1 = write_netcdf(assy, str(netcdf_path)) | ||
assert netcdf_path.exists() | ||
|
||
|
||
def test_reset_index(): | ||
assy = DataAssembly( | ||
data=[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]], | ||
coords={ | ||
'up': ("a", ['alpha', 'alpha', 'beta', 'beta', 'beta', 'beta']), | ||
'down': ("a", [1, 1, 1, 1, 2, 2]), | ||
'sideways': ('b', ['x', 'y', 'z']) | ||
}, | ||
dims=['a', 'b'] | ||
) | ||
assert assy["a"].variable.level_names == ["up", "down"] | ||
assert list(assy.indexes) == ["a", "b"] | ||
assy = assy.reset_index(list(assy.indexes)) | ||
assert assy["a"].variable.level_names is None | ||
assert get_levels(assy) == [] | ||
assert list(assy.indexes) == [] | ||
|
||
|
||
|
||
def test_reset_index_levels(): | ||
assy = DataAssembly( | ||
data=[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]], | ||
coords={ | ||
'up': ("a", ['alpha', 'alpha', 'beta', 'beta', 'beta', 'beta']), | ||
'down': ("a", [1, 1, 1, 1, 2, 2]), | ||
'sideways': ('b', ['x', 'y', 'z']) | ||
}, | ||
dims=['a', 'b'] | ||
) | ||
assert assy["a"].variable.level_names == ["up", "down"] | ||
assy = assy.reset_index(["up", "down"]) | ||
assert get_levels(assy) == [] | ||
|
||
|
||
|