Skip to content

Commit

Permalink
Fix typing for histogram scalar division
Browse files Browse the repository at this point in the history
The division was already supported - the typing just needed to be
updated (following the example of scalar multiplication).
  • Loading branch information
raymondEhlers committed Oct 20, 2019
1 parent 306adae commit 7cc7a7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pachyderm/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,20 +500,23 @@ def __imul__(self: _T, other: Union[_T, float]) -> _T:
self.y *= other.y
return self

def __truediv__(self: _T, other: _T) -> _T:
def __truediv__(self: _T, other: Union[_T, float]) -> _T:
""" Handles ``a = b / c``. """
new = self.copy()
new /= other
return new

def __itruediv__(self: _T, other: _T) -> _T:
def __itruediv__(self: _T, other: Union[_T, float]) -> _T:
""" Handles ``a /= b``. """
if np.isscalar(other):
# Help out mypy...
assert isinstance(other, (float, int, np.number))
# Scale histogram by a scalar
self *= 1. / other
else:
# Help out mypy...
assert isinstance(other, Histogram1D)
# Validation
if not np.allclose(self.bin_edges, other.bin_edges):
raise TypeError(
f"Binning is different for given histograms."
Expand Down

0 comments on commit 7cc7a7e

Please sign in to comment.