Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beginning with version 2.6, python supports abstract base classes, which contain a class hierarchy for numbers. This class hierarchy is very similar to the one of numpy, so it is very easy to register the numpy type hierarchy with the python type hierarchy. This patch adds those registrations and also adds unit tests for it.
- Loading branch information
Martin Teichmann
committed
Mar 25, 2014
1 parent
8409b4c
commit 2d73ff3
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import division, absolute_import, print_function | ||
|
||
import numpy as np | ||
from numpy.testing import TestCase, assert_ | ||
|
||
import numbers | ||
from numpy.core.numerictypes import sctypes | ||
|
||
class ABC(TestCase): | ||
def test_floats(self): | ||
for t in sctypes['float']: | ||
assert_(isinstance(t(), numbers.Real), | ||
"{0} is not instance of Real".format(t.__name__)) | ||
assert_(issubclass(t, numbers.Real), | ||
"{0} is not subclass of Real".format(t.__name__)) | ||
assert_(not isinstance(t(), numbers.Rational), | ||
"{0} is instance of Rational".format(t.__name__)) | ||
assert_(not issubclass(t, numbers.Rational), | ||
"{0} is subclass of Rational".format(t.__name__)) | ||
|
||
def test_complex(self): | ||
for t in sctypes['complex']: | ||
assert_(isinstance(t(), numbers.Complex), | ||
"{0} is not instance of Complex".format(t.__name__)) | ||
assert_(issubclass(t, numbers.Complex), | ||
"{0} is not subclass of Complex".format(t.__name__)) | ||
assert_(not isinstance(t(), numbers.Real), | ||
"{0} is instance of Real".format(t.__name__)) | ||
assert_(not issubclass(t, numbers.Real), | ||
"{0} is subclass of Real".format(t.__name__)) | ||
|
||
def test_int(self): | ||
for t in sctypes['int']: | ||
assert_(isinstance(t(), numbers.Integral), | ||
"{0} is not instance of Integral".format(t.__name__)) | ||
assert_(issubclass(t, numbers.Integral), | ||
"{0} is not subclass of Integral".format(t.__name__)) | ||
|
||
def test_uint(self): | ||
for t in sctypes['uint']: | ||
assert_(isinstance(t(), numbers.Integral), | ||
"{0} is not instance of Integral".format(t.__name__)) | ||
assert_(issubclass(t, numbers.Integral), | ||
"{0} is not subclass of Integral".format(t.__name__)) | ||
|