def is_integer(x):
"""Determine whether some object ``x`` is an
integer type (int, long, etc).
Parameters
----------
x : object
The item to assess
Returns
-------
bool
True if ``x`` is an integer type
"""
try:
python_major_version = sys.version_info.major
assert(python_major_version == 2 or python_major_version == 3)
if python_major_version == 2:
return (not isinstance(x, (bool, np.bool))) and \
isinstance(x, (numbers.Integral, int, long, np.int, np.long))
elif python_major_version == 3:
return (not isinstance(x, (bool, np.bool))) and \
isinstance(x, (numbers.Integral, int, np.int, np.long))
except AssertionError:
_, _, tb = sys.exc_info()
traceback.print_tb(tb) # Fixed format
tb_info = traceback.extract_tb(tb)
filename, line, func, text = tb_info[-1]
print('An error occurred on line {} in statement {}'.format(line, text))
exit(1)
return _is_integer(x)
评论列表
文章目录