diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-10-24 12:43:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 12:43:02 -0600 |
commit | 3e61cb4526c1155c70d64c824a82d78d3ea02e7d (patch) | |
tree | 4833850c97fc1fcda1881a247378f012bb4b4824 /numpy/core/numeric.py | |
parent | 24f1b3b7638377ce3474c459851db6a123c5da6f (diff) | |
parent | c0db59fe1afcf67e4c6c3b0c8034974ef008704f (diff) | |
download | numpy-3e61cb4526c1155c70d64c824a82d78d3ea02e7d.tar.gz |
Merge pull request #9691 from jdemeyer/master
PEP 3141 numbers should be considered scalars
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 1f8f5d43e..bf3f43444 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -5,6 +5,7 @@ import itertools import operator import sys import warnings +import numbers import numpy as np from . import multiarray @@ -1936,11 +1937,19 @@ def isscalar(num): >>> np.isscalar('numpy') True + NumPy supports PEP 3141 numbers: + + >>> from fractions import Fraction + >>> isscalar(Fraction(5, 17)) + True + >>> from numbers import Number + >>> isscalar(Number()) + True + """ - if isinstance(num, generic): - return True - else: - return type(num) in ScalarType + return (isinstance(num, generic) + or type(num) in ScalarType + or isinstance(num, numbers.Number)) def binary_repr(num, width=None): |