Skip to content

Commit

Permalink
remove some of the pylint exceptions, fix the resulting style errors (#4
Browse files Browse the repository at this point in the history
)

* no longer disabling `len-as-condition` and `no-else-return`
  • Loading branch information
mgeplf authored May 11, 2022
1 parent d658235 commit 03ddb56
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MESSAGES CONTROL]
disable=bad-continuation,fixme,invalid-name,len-as-condition,no-else-return
disable=bad-continuation,fixme,invalid-name

[FORMAT]
# Regexp for a line that is allowed to be longer than the limit.
Expand Down
9 changes: 6 additions & 3 deletions voxcell/nexus/voxelbrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ def open(url, cache_dir=None):
parsed = urllib.parse.urlsplit(url)
if parsed.scheme in ('', 'file'):
return LocalAtlas(url)
elif parsed.scheme in ('http', 'https'):

if parsed.scheme in ('http', 'https'):
if not parsed.path.startswith('/api/analytics/atlas/releases/'):
raise VoxcellError(f"Unexpected URL: '{url}'")

if cache_dir is None:
raise VoxcellError("`cache_dir` should be specified")

return VoxelBrainAtlas(url, cache_dir)
else:
raise VoxcellError(f"Unexpected URL: '{url}'")

raise VoxcellError(f"Unexpected URL: '{url}'")

@abc.abstractmethod
def fetch_data(self, data_type):
Expand Down
11 changes: 6 additions & 5 deletions voxcell/region_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def __call__(self, value):
"""Return True if the given value matches."""
if hasattr(self.value, 'match'):
return bool(self.value.search(value))
elif isinstance(value, str) and self.ignore_case:

if isinstance(value, str) and self.ignore_case:
return self.value.upper() == value.upper()
else:
return self.value == value

return self.value == value


class RegionMap:
Expand Down Expand Up @@ -62,8 +63,8 @@ def get(self, _id, attr, with_ascendants=False):
"""
if with_ascendants:
return [self._get(k, attr) for k in self._ascendants(_id)]
else:
return self._get(_id, attr)

return self._get(_id, attr)

def find(self, value, attr, ignore_case=False, with_descendants=False):
"""Find IDs of the regions matching a given attribute.
Expand Down
4 changes: 2 additions & 2 deletions voxcell/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def collect(self, positions, preassigned=None, names=None):
"""
if preassigned is None:
return self.collect_traits(self.assign(positions), names)
else:
return self.collect_traits(self.assign_conditional(positions, preassigned), names)

return self.collect_traits(self.assign_conditional(positions, preassigned), names)

def collect_traits(self, chosen, names=None):
"""Return the trait values corresponding to an array of indices.
Expand Down
19 changes: 9 additions & 10 deletions voxcell/vector_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,19 @@ def combine_vector_fields(fields):
Returns:
A 5D numpy array representing an orientation field
"""
if fields:
shape = fields[0].shape
if not fields:
return np.empty((0,))

# add a second-to-last dimension: the number of fields
result = np.zeros(shape=shape[:-1] + (len(fields),) + (shape[-1],), dtype=fields[0].dtype)
shape = fields[0].shape

# abusing numpy broadcasting here saves us having to do an explicit transpose afterwards
for i, f in enumerate(fields):
result[..., i] = f
# add a second-to-last dimension: the number of fields
result = np.zeros(shape=shape[:-1] + (len(fields),) + (shape[-1],), dtype=fields[0].dtype)

return result
# abusing numpy broadcasting here saves us having to do an explicit transpose afterwards
for i, f in enumerate(fields):
result[..., i] = f

else:
return np.empty((0,))
return result


def split_orientation_field(field):
Expand Down
21 changes: 11 additions & 10 deletions voxcell/voxel_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ def clip(self, bbox, na_value=0, inplace=False):
mask[indices] = True
self.raw[np.logical_not(mask)] = na_value
return None
else:
raw = np.full_like(self.raw, na_value)
raw[indices] = self.raw[indices]
return VoxelData(raw, self.voxel_dimensions, self.offset)

raw = np.full_like(self.raw, na_value)
raw[indices] = self.raw[indices]
return VoxelData(raw, self.voxel_dimensions, self.offset)

def filter(self, predicate, inplace=False):
"""Set values for voxel positions not satisfying `predicate` to zero.
Expand All @@ -284,13 +284,14 @@ def filter(self, predicate, inplace=False):
ijk = np.stack(np.mgrid[[slice(0, d) for d in self.shape]], axis=-1)
xyz = self.indices_to_positions(0.5 + ijk)
mask = predicate(xyz.reshape(-1, self.ndim)).reshape(self.shape)

if inplace:
self.raw[np.invert(mask)] = 0
return None
else:
raw = np.zeros_like(self.raw)
raw[mask] = self.raw[mask]
return VoxelData(raw, self.voxel_dimensions, self.offset)

raw = np.zeros_like(self.raw)
raw[mask] = self.raw[mask]
return VoxelData(raw, self.voxel_dimensions, self.offset)

def compact(self, na_values=(0,), inplace=False):
"""Reduce size of raw data by clipping N/A values.
Expand All @@ -314,8 +315,8 @@ def compact(self, na_values=(0,), inplace=False):
self.raw = raw
self.offset = offset
return None
else:
return VoxelData(raw, self.voxel_dimensions, offset)

return VoxelData(raw, self.voxel_dimensions, offset)

def with_data(self, raw):
"""Return VoxelData of the same shape with different data."""
Expand Down

0 comments on commit 03ddb56

Please sign in to comment.