-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix OMX construction with arbitrary zone ids (#27)
* fallback to dynamic version * version infer * fix dataset from_omx for arbitrary zone ids
- Loading branch information
Showing
5 changed files
with
83 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
try: | ||
from ._version import __version__, __version_tuple__ | ||
except ImportError: | ||
# Package is not "installed", parse git tag at runtime | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
try: | ||
__version__ = version(__package__) | ||
except PackageNotFoundError: | ||
# package is not installed | ||
__version__ = "999.999" | ||
|
||
__version_tuple__ = __version__.split(".") |
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,37 @@ | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import openmatrix | ||
from pytest import approx | ||
|
||
import sharrow as sh | ||
|
||
|
||
def test_dataset_construct_with_zoneids(): | ||
tempdir = tempfile.TemporaryDirectory() | ||
t = Path(tempdir.name) | ||
|
||
with openmatrix.open_file(t.joinpath("dummy5.omx"), mode="w") as out: | ||
out.create_carray("/data", "Eye", obj=np.eye(5, dtype=np.float32)) | ||
out.create_carray("/lookup", "Zone", obj=np.asarray([11, 22, 33, 44, 55])) | ||
shp = np.empty(2, dtype=int) | ||
shp[0] = 5 | ||
shp[1] = 5 | ||
out.root._v_attrs.SHAPE = shp | ||
|
||
with openmatrix.open_file(t.joinpath("dummy5.omx"), mode="r") as back: | ||
ds = sh.dataset.from_omx(back, indexes="Zone") | ||
|
||
assert sorted(ds.coords) == ["dtaz", "otaz"] | ||
assert ds.coords["otaz"].values == approx(np.asarray([11, 22, 33, 44, 55])) | ||
assert sorted(ds.variables) == ["Eye", "dtaz", "otaz"] | ||
assert ds["Eye"].data == approx(np.eye(5, dtype=np.float32)) | ||
|
||
with openmatrix.open_file(t.joinpath("dummy5.omx"), mode="r") as back: | ||
ds0 = sh.dataset.from_omx(back, indexes="zero-based") | ||
assert ds0.coords["otaz"].values == approx(np.asarray([0, 1, 2, 3, 4])) | ||
|
||
with openmatrix.open_file(t.joinpath("dummy5.omx"), mode="r") as back: | ||
ds1 = sh.dataset.from_omx(back, indexes="one-based") | ||
assert ds1.coords["otaz"].values == approx(np.asarray([1, 2, 3, 4, 5])) |