From 182d545d74906cc25d5fea81502b219d640d1939 Mon Sep 17 00:00:00 2001 From: DanRyanIrish Date: Mon, 9 Dec 2024 13:08:00 +0000 Subject: [PATCH] Fix codestyle. --- ndcube/meta.py | 12 ++++++------ ndcube/ndcollection.py | 1 + ndcube/tests/test_meta.py | 12 ++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ndcube/meta.py b/ndcube/meta.py index 19e2973c2..27b9a2a63 100644 --- a/ndcube/meta.py +++ b/ndcube/meta.py @@ -6,7 +6,7 @@ import numpy as np -__all__ = ["NDMetaABC", "NDMeta"] +__all__ = ["NDMeta", "NDMetaABC"] class NDMetaABC(collections.abc.Mapping): @@ -157,7 +157,7 @@ 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( @@ -165,14 +165,14 @@ def __init__(self, meta=None, key_comments=None, axes=None, data_shape=None): 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( "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 " @@ -183,7 +183,7 @@ def _sanitize_axis_value(self, axis, value, key): return ValueError(axis_err_msg) # 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) # If metadata's axis/axes include axis beyond current data shape, extend it. data_shape = self.data_shape diff --git a/ndcube/ndcollection.py b/ndcube/ndcollection.py index 468a399ee..91df04b27 100644 --- a/ndcube/ndcollection.py +++ b/ndcube/ndcollection.py @@ -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): diff --git a/ndcube/tests/test_meta.py b/ndcube/tests/test_meta.py index b2c9dc7e6..a553360cc 100644 --- a/ndcube/tests/test_meta.py +++ b/ndcube/tests/test_meta.py @@ -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 @@ -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"] @@ -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)