Skip to content

Commit

Permalink
improve _translate_columns
Browse files Browse the repository at this point in the history
- use for-else logic
- update docstring for `__contains__`
  • Loading branch information
jianyangli committed Jul 19, 2022
1 parent 67c4292 commit 8241a98
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions sbpy/data/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def __setitem__(self, ident, val):
self.table.__setitem__(ident, val)

def __contains__(self, value):
"""Use cls._translate_columns to realize the `in` operator"""
"""To support `in` operator that allows for alternative names"""
if (value in self.table.colnames) or \
(value in sum([Conf.fieldnames[Conf.fieldname_idx.get(x, slice(0))]
for x in self.table.colnames], [])):
Expand All @@ -679,14 +679,12 @@ def _translate_columns(self, target_colnames):
continue
# colname is an alternative column name
else:
found = False
for alt in Conf.fieldnames[
Conf.fieldname_idx.get(colname, slice(0))]:
if alt in self.field_names:
translated_colnames[idx] = alt
found = True
break
if not found:
else:
raise KeyError('field "{:s}" not available.'.format(
colname))

Expand Down

0 comments on commit 8241a98

Please sign in to comment.