[Numpy-discussion] PyInt and Numpy's int64 conversion

Wes McKinney wesmckinn at gmail.com
Fri Dec 23 12:31:45 EST 2011

On Fri, Dec 23, 2011 at 4:37 AM, xantares 09 <xantares09 at hotmail.com> wrote:
> Hi,
> I'm using Numpy from the C python api side while tweaking my SWIG interface
> to work with numpy array types.
> I want to convert a numpy array of integers (whose elements are numpy's
> 'int64')
> The problem is that it this int64 type is not compatible with the standard
> python integer type:
> I cannot use PyInt_Check, and PyInt_AsUnsignedLongMask to check and convert
> from int64: basically PyInt_Check returns false.
> I checked the numpy config header and npy_int64 does have a size of 8o,
> which should be the same as int on my x86_64.
> What is the correct way to do that ?
> I checked for a Int64_Check function and didn't find any in numpy headers.
> Regards,
> x.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


I think you'll want to use the C macro PyArray_IsIntegerScalar, e.g.
in pandas I have the following function exposed to my Cython code:

is_integer_object(PyObject* obj) {
  return PyArray_IsIntegerScalar(obj);

last time I checked that macro detects Python int, long, and all of
the NumPy integer hierarchy (int8, 16, 32, 64). If you ONLY want to
check for int64 I am not 100% sure the best way.

- Wes

More information about the NumPy-Discussion mailing list