Skip to content

Commit

Permalink
chore: make pre-commit happy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejnovak committed Jan 19, 2022
1 parent 88f9e08 commit 7953d2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/boost_histogram/_internal/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def _isstr(value: Any) -> bool:
"""
Check to see if this is a stringlike or a (nested) iterable of stringlikes
"""

if isinstance(value, (str, bytes)):
return True
elif hasattr(value, "__iter__"):
Expand All @@ -37,25 +36,25 @@ def _isstr(value: Any) -> bool:
return False


def _flatten(x):
if hasattr(x, '__iter__') and not isinstance(x, (str, bytes)):
def _flatten(x: Any) -> List[Any]:
if hasattr(x, "__iter__") and not isinstance(x, (str, bytes)):
return [a for i in x for a in _flatten(i)]
else:
return [x]


def _missing(value: Any, ax: "Axis") -> bool:
def _missing(value: Any, ax: "Axis") -> Union[None, List[Any]]:
"""
Return value(s) that are not part of index.
"""
if isinstance(value, (int, str, bytes)):
parsed = [value]
elif hasattr(value, "__iter__"):
if isinstance(value, np.ndarray):
parsed = value.ravel()
parsed = [v for v in value.ravel()]
else:
parsed = _flatten(value)
missing = [p for p in parsed if p not in ax]
missing = [p for p in parsed if p not in list(ax)]
if len(missing) > 0:
return missing
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,13 @@ def test_index(self):
a = bh.axis.Integer(-1, 3)
with pytest.raises(Exception):
a.index(-3)
with pytest.raises(Exception):
a.index(-2)
with pytest.raises(Exception):
a.index(-2)
assert a.index(-1) == 0
assert a.index(0) == 1
assert a.index(1) == 2
assert a.index(2) == 3
with pytest.raises(Exception):
with pytest.raises(Exception):
a.index(3)
with pytest.raises(Exception):
a.index(4)
Expand Down

0 comments on commit 7953d2a

Please sign in to comment.