Skip to content

Commit ee3ac7b

Browse files
committed
Fix handling of int dtype
- Seems like some versions of numpy behave inconsistently
1 parent 2b05530 commit ee3ac7b

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

datamatrix/_datamatrix/_numericcolumn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def _tosequence(self, value, length=None):
321321
pass
322322
else:
323323
return super(NumericColumn, self)._tosequence(value, length)
324+
return super(NumericColumn, self)._tosequence(value, length)
324325
value = self._checktype(value)
325326
return super(NumericColumn, self)._tosequence(value, length)
326327

@@ -370,7 +371,7 @@ def _operate(self, other, number_op, str_op=None, flip=False):
370371
def __eq__(self, other):
371372

372373
if isinstance(other, type):
373-
if other is self.dtype:
374+
if other == self.dtype:
374375
return self._datamatrix
375376
return self._datamatrix._selectrowid(Index(0))
376377
if self._issequence(other):
@@ -387,7 +388,7 @@ def __eq__(self, other):
387388
def __ne__(self, other):
388389

389390
if isinstance(other, type):
390-
if other is not self.dtype:
391+
if other != self.dtype:
391392
return self._datamatrix
392393
return self._datamatrix._selectrowid(Index(0))
393394
if self._issequence(other):

testcases/test_basics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def _test_numericcolumn(cls):
8080
dm.col = 1, 2, 3, 4, 5
8181
# int -> float
8282
val = dm.col[2]
83-
assert isinstance(val, (int, float))
83+
# In some versions of numpy, np.int32/64 don't match regular ints. For float
84+
# this isn't an issue.
85+
assert isinstance(val, (np.int64, np.int32, int, float))
8486
assert val == 3
8587
# (int, int) -> FloatColumn
8688
val = dm.col[1, 3]

testcases/test_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def check_intcolumn_typing():
116116

117117
dm = DataMatrix(length=4, default_col_type=IntColumn)
118118
dm.f = 1.1, '1.8', 2, '2'
119-
assert all(isinstance(v, int) for v in dm.f)
119+
assert all(isinstance(v, (int, np.int32, np.int64)) for v in dm.f)
120120
def _():
121121
with pytest.raises(TypeError):
122122
dm.inf = INF, -INF, 'inf', '-inf'

0 commit comments

Comments
 (0)