Commit 50bc7693 authored by dboe's avatar dboe
Browse files

linting

parent cfb1262a
Pipeline #85980 passed with stages
in 56 seconds
......@@ -69,7 +69,7 @@ class AbstractObject(object): # pylint: disable=useless-object-inheritance
Saving by redirecting to the correct save method depending on path
Args:
path (str or buffer)
path (str | buffer)
*args: joined with path
**kwargs:
extension (str): only needed if path is buffer
......@@ -357,7 +357,8 @@ class AbstractNdarray(np.ndarray, AbstractObject):
**kwargs: arguments corresponding to __slots__
TODO:
equality check
* equality check
* plot
"""
......@@ -677,12 +678,12 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
def __new__(cls, tensors, **kwargs): # pylint: disable=too-many-branches
dtype = kwargs.pop("dtype", None)
order = kwargs.pop("order", None)
dim = kwargs.pop("dim", None) # pylint: disable=redefined-outer-name
dim_ = kwargs.pop("dim", None)
# copy constructor extracts the kwargs from tensors
if issubclass(type(tensors), Tensors):
if dim is not None:
dim = tensors.dim
if dim_ is not None:
dim_ = tensors.dim
coord_sys = kwargs.pop("coord_sys", tensors.coord_sys)
tensors = tensors.copy()
tensors.transform(coord_sys)
......@@ -709,13 +710,13 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
if len(tensors) == 0:
if issubclass(type(tensors), tfields.Tensors):
tensors = np.empty(tensors.shape, dtype=tensors.dtype)
elif dim is not None:
tensors = np.empty((0, dim))
elif dim_ is not None:
tensors = np.empty((0, dim_))
if issubclass(type(tensors), np.ndarray):
# np.empty
pass
elif hasattr(tensors, "shape"):
dim = dim(tensors)
dim_ = dim_(tensors)
else:
raise ValueError("Empty tensors need dimension parameter 'dim'.")
......@@ -732,11 +733,11 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
found=obj.shape[1:], **locals()
)
)
if dim is not None:
if dim != obj.dim:
if dim_ is not None:
if dim_ != obj.dim:
raise ValueError(
"Incorrect dimension: {obj.dim} given,"
" {dim} demanded.".format(**locals())
" {dim_} demanded.".format(**locals())
)
# update kwargs with defaults from slots
......@@ -1920,13 +1921,13 @@ class TensorFields(Tensors):
@classmethod
def merged(cls, *objects, **kwargs):
if not all([isinstance(o, cls) for o in objects]):
types = [ # pylint: disable=possibly-unused-variable
type(o) for o in objects
]
# Note: could allow if all map_fields are none
raise TypeError(
"Merge constructor only accepts {cls} instances."
"Got objects of types {types} instead.".format(**locals())
"Got objects of types {types} instead.".format(
cls=cls,
types=[type(o) for o in objects],
)
)
return_value = super(TensorFields, cls).merged(*objects, **kwargs)
......@@ -2156,28 +2157,28 @@ class Maps(sortedcontainers.SortedDict, AbstractObject):
super().__init__(*args, **kwargs)
@staticmethod
def to_map(mp, *fields, copy=False, **kwargs): # pylint: disable=invalid-name
def to_map(map_, *fields, copy=False, **kwargs):
"""
Args:
mp (TensorFields)
map_ (TensorFields)
*fields (Tensors)
copy (bool)
**kwargs: passed to TensorFields constructor
"""
if not copy:
if isinstance(mp, TensorFields) and not fields:
if not np.issubdtype(mp.dtype, np.integer):
mp = mp.astype(int)
if isinstance(map_, TensorFields) and not fields:
if not np.issubdtype(map_.dtype, np.integer):
map_ = map_.astype(int)
else:
copy = True
if copy: # not else, because in case of wrong mp type we initialize
if copy: # not else, because in case of wrong map_ type we initialize
kwargs.setdefault("dtype", int)
mp = TensorFields(mp, *fields, **kwargs)
return mp
map_ = TensorFields(map_, *fields, **kwargs)
return map_
def __setitem__(self, dimension, mp):
mp = self.to_map(mp)
super().__setitem__(dimension, mp)
def __setitem__(self, dimension, map_):
map_ = self.to_map(map_)
super().__setitem__(dimension, map_)
def _args(self):
return super()._args() + (list(self.items()),)
......@@ -2315,10 +2316,10 @@ class TensorMaps(TensorFields):
map_delete_mask = np.full(
(len(self.maps[map_dim]),), False, dtype=bool
)
for i, mp in enumerate( # pylint: disable=invalid-name
for i, map_ in enumerate( # pylint: disable=invalid-name
self.maps[map_dim]
):
for node_index in mp:
for node_index in map_:
if node_index in delete_indices:
map_delete_mask[i] = True
break
......@@ -2354,13 +2355,13 @@ class TensorMaps(TensorFields):
else:
inst, templates = (return_value, None)
dim_maps_dict = {} # {dim: {i: mp}
dim_maps_dict = {} # {dim: {i: map_}
for i, obj in enumerate(objects):
for dimension, mp in obj.maps.items(): # pylint: disable=invalid-name
mp = mp + cum_tensor_lengths[i] # pylint: disable=invalid-name
for dimension, map_ in obj.maps.items(): # pylint: disable=invalid-name
map_ = map_ + cum_tensor_lengths[i] # pylint: disable=invalid-name
if dimension not in dim_maps_dict:
dim_maps_dict[dimension] = {}
dim_maps_dict[dimension][i] = mp
dim_maps_dict[dimension][i] = map_
maps = []
template_maps_list = [[] for i in range(len(objects))]
......@@ -2374,7 +2375,7 @@ class TensorMaps(TensorFields):
)
if return_templates:
(
mp, # pylint: disable=invalid-name
map_, # pylint: disable=invalid-name
dimension_map_templates,
) = return_value
for i in range(len(objects)):
......@@ -2382,8 +2383,8 @@ class TensorMaps(TensorFields):
(dimension, dimension_map_templates[i])
)
else:
mp = return_value # pylint: disable=invalid-name
maps.append(mp)
map_ = return_value # pylint: disable=invalid-name
maps.append(map_)
inst.maps = maps
if return_templates: # pylint: disable=no-else-return
......@@ -2438,16 +2439,16 @@ class TensorMaps(TensorFields):
# bulk was cut so we need to correct the map references.
index_lut = np.full(len(self), np.nan) # float type
index_lut[template.fields[0]] = np.arange(len(template.fields[0]))
for mp_dim, mp in self.maps.items(): # pylint: disable=invalid-name
mp = mp._cut_template( # pylint: disable=invalid-name,protected-access
template.maps[mp_dim]
for map_dim, map_ in self.maps.items():
map_ = map_._cut_template( # pylint: disable=protected-access
template.maps[map_dim]
)
if template.fields:
# correct
mp = Maps.to_map( # pylint: disable=invalid-name
index_lut[mp], *mp.fields
map_ = Maps.to_map( # pylint: disable=invalid-name
index_lut[map_], *map_.fields
)
inst.maps[mp_dim] = mp
inst.maps[map_dim] = map_
return inst
def equal(self, other, **kwargs):
......@@ -2557,12 +2558,10 @@ class TensorMaps(TensorFields):
# self.maps in case stale vertices where removed
for map_dim in inst.maps:
for face_index in range(len(inst.maps[map_dim])): # face index
mp = np.array( # noqa: E501 pylint: disable=invalid-name
inst.maps[map_dim], dtype=int
)
if tensor_index in mp[face_index]:
map_ = np.array(inst.maps[map_dim], dtype=int)
if tensor_index in map_[face_index]:
index = tfields.lib.util.index(
mp[face_index], tensor_index
map_[face_index], tensor_index
)
inst.maps[map_dim][face_index][index] = duplicate_index
if remove_mask.any():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment