Skip to content

Commit

Permalink
Fix codestyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRyanIrish committed Dec 9, 2024
1 parent f681b95 commit 182d545
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions ndcube/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

__all__ = ["NDMetaABC", "NDMeta"]
__all__ = ["NDMeta", "NDMetaABC"]


class NDMetaABC(collections.abc.Mapping):
Expand Down Expand Up @@ -157,22 +157,22 @@ def __init__(self, meta=None, key_comments=None, axes=None, data_shape=None):
meta_keys = meta.keys()

if key_comments is None:
self._key_comments = dict()
self._key_comments = {}
else:
if not set(key_comments.keys()).issubset(set(meta_keys)):
raise ValueError(

Check warning on line 163 in ndcube/meta.py

View check run for this annotation

Codecov / codecov/patch

ndcube/meta.py#L163

Added line #L163 was not covered by tests
"All comments must correspond to a value in meta under the same key.")
self._key_comments = key_comments

if axes is None:
self._axes = dict()
self._axes = {}
else:
axes = dict(axes)
if not set(axes.keys()).issubset(set(meta_keys)):
raise ValueError(

Check warning on line 172 in ndcube/meta.py

View check run for this annotation

Codecov / codecov/patch

ndcube/meta.py#L172

Added line #L172 was not covered by tests
"All axes must correspond to a value in meta under the same key.")
self._axes = dict([(key, self._sanitize_axis_value(axis, meta[key], key))
for key, axis in axes.items()])
self._axes = {key:self._sanitize_axis_value(axis, meta[key], key)
for key, axis in axes.items()}

def _sanitize_axis_value(self, axis, value, key):
axis_err_msg = ("Values in axes must be an integer or iterable of integers giving "
Expand All @@ -183,7 +183,7 @@ def _sanitize_axis_value(self, axis, value, key):
return ValueError(axis_err_msg)

Check warning on line 183 in ndcube/meta.py

View check run for this annotation

Codecov / codecov/patch

ndcube/meta.py#L183

Added line #L183 was not covered by tests
# Verify each entry in axes is an iterable of ints or a scalar.
if not (isinstance(axis, collections.abc.Iterable)
and all([isinstance(i, numbers.Integral) for i in axis])):
and all(isinstance(i, numbers.Integral) for i in axis)):
return ValueError(axis_err_msg)

Check warning on line 187 in ndcube/meta.py

View check run for this annotation

Codecov / codecov/patch

ndcube/meta.py#L187

Added line #L187 was not covered by tests
# If metadata's axis/axes include axis beyond current data shape, extend it.
data_shape = self.data_shape
Expand Down
1 change: 1 addition & 0 deletions ndcube/ndcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def aligned_dimensions(self):
return np.asanyarray(self[self._first_key].shape, dtype=object)[
np.array(self.aligned_axes[self._first_key])
]
return None

@property
def aligned_axis_physical_types(self):
Expand Down
12 changes: 6 additions & 6 deletions ndcube/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def test_slice_away_independent_axis(basic_meta):
meta = basic_meta
item = 0
output = meta.slice[item]
values = dict([(key, value) for key, value in meta.items()])
values = dict(meta.items())
values["b"] = values["b"][0]
values["g"] = ["world", "!"]
del values["f"]
key_comments = meta.key_comments
axes = dict([(key, axis) for key, axis in meta.axes.items()])
axes = copy.deepcopy(meta.axes)
del axes["b"]
del axes["f"]
axes["c"] -= 1
Expand All @@ -93,14 +93,14 @@ def test_slice_away_independent_and_dependent_axis(basic_meta):
meta = basic_meta
item = (0, 1)
output = meta.slice[item]
values = dict([(key, value) for key, value in meta.items()])
values = dict(meta.items())
del values["f"]
values["b"] = values["b"][0]
values["c"] = values["c"][1]
values["e"] = values["e"][1]
values["g"] = "!"
key_comments = meta.key_comments
axes = dict([(key, axis) for key, axis in meta.axes.items()])
axes = copy.deepcopy(meta.axes)
del axes["b"]
del axes["e"]
del axes["f"]
Expand All @@ -114,13 +114,13 @@ def test_slice_away_independent_and_dependent_axis(basic_meta):
def test_slice_dependent_axes(basic_meta):
meta = basic_meta
output = meta.slice[:, 1:3, :, 1]
values = dict([(key, value) for key, value in meta.items()])
values = dict(meta.items())
values["c"] = values["c"][1:3, 1]
values["d"] = values["d"][1]
values["e"] = values["e"][1:3]
values["g"] = values["g"][:2]
key_comments = meta.key_comments
axes = dict([(key, axis) for key, axis in meta.axes.items()])
axes = copy.deepcopy(meta.axes)
del axes["d"]
axes["c"] = 1
axes["g"] = (0, 1)
Expand Down

0 comments on commit 182d545

Please sign in to comment.