Skip to content

Commit

Permalink
FIX: Coerce dtype in Layout.get
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Aug 21, 2018
1 parent eb37ef7 commit 307aa37
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions grabbit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ def match_file(self, f, update_file=False):
m = self.regex.search(f.path)
val = m.group(1) if m is not None else None

if val is not None and self.dtype is not None:
val = self.dtype(val)

return val
return self._astype(val)

def add_file(self, filename, value):
""" Adds the specified filename to tracking. """
Expand All @@ -296,6 +293,11 @@ def count(self, files=False):
"""
return len(self.files) if files else len(self.unique())

def _astype(self, val):
if val is not None and self.dtype is not None:
val = self.dtype(val)
return val


class Layout(object):

Expand Down Expand Up @@ -860,7 +862,7 @@ def get_nearest(self, path, return_type='file', strict=True, all_=False,
for ent in self.entities.values():
m = ent.regex.search(path)
if m:
entities[ent.name] = m.group(1)
entities[ent.name] = ent._astype(m.group(1))

# Remove any entities we want to ignore when strict matching is on
if strict and ignore_strict_entities is not None:
Expand Down

0 comments on commit 307aa37

Please sign in to comment.