Skip to content

Commit 2186a7e

Browse files
authored
Merge pull request python-quantities#207 from apdavison/fix-floordiv
fix failure to handle units with floordiv
2 parents a6e3fe8 + 99448bd commit 2186a7e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

quantities/dimensionality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def _d_divide(q1, q2, out=None):
238238
return q2.dimensionality**-1
239239
p_dict[np.divide] = _d_divide
240240
p_dict[np.true_divide] = _d_divide
241+
p_dict[np.floor_divide] = _d_divide
241242

242243
def _d_check_uniform(q1, q2, out=None):
243244
try:
@@ -273,7 +274,6 @@ def _d_check_uniform(q1, q2, out=None):
273274
p_dict[np.mod] = _d_check_uniform
274275
p_dict[np.fmod] = _d_check_uniform
275276
p_dict[np.remainder] = _d_check_uniform
276-
p_dict[np.floor_divide] = _d_check_uniform
277277
p_dict[np.hypot] = _d_check_uniform
278278
p_dict[np.equal] = _d_check_uniform
279279
p_dict[np.not_equal] = _d_check_uniform

quantities/tests/test_arithmetic.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class iter_dtypes:
5252

5353
def __init__(self):
5454
self._i = 1
55-
self._typeDict = np.typeDict.copy()
55+
self._typeDict = np.sctypeDict.copy()
5656
self._typeDict[17] = int
5757
self._typeDict[18] = long
5858
self._typeDict[19] = float
@@ -132,6 +132,20 @@ def test_mul(self):
132132
self.check_rmul(x, y)
133133
dtypes.pop(0)
134134

135+
def test_truediv(self):
136+
q = Quantity([44, 40, 36, 32], units=pq.ms)
137+
self.assertQuantityEqual(
138+
q/(4 * pq.ms),
139+
Quantity([11, 10, 9, 8], units=pq.dimensionless)
140+
)
141+
142+
def test_floordiv(self):
143+
q = Quantity([45, 43, 39, 32], units=pq.ms)
144+
self.assertQuantityEqual(
145+
q//(4 * pq.ms),
146+
Quantity([11, 10, 9, 8], units=pq.dimensionless)
147+
)
148+
135149
def test_mixed_addition(self):
136150
self.assertQuantityEqual(1*pq.ft + 1*pq.m, 4.280839895 * pq.ft)
137151
self.assertQuantityEqual(1*pq.ft + pq.m, 4.280839895 * pq.ft)

0 commit comments

Comments
 (0)