When writing python code for numpy arrays you can see the resolution of a given datetime64 array using its dtype for example
>>> np.array(np.datetime64('2001-01-01'), np.datetime64('2001-01-02')).dtype
dtype('<M8[D]')
>>> np.array(np.datetime64('2001-01'), np.datetime64('2001-02')).dtype
dtype('<M8[M]')
The dtype specifies if the resolution is days or months. But using the numpy C API I cant seem to figure out what struct member holds this resolution information.
// obj is the numpy array
// e.g. np.array(np.datetime64('2001-01-01'), np.datetime64('2001-01-02'))
PyArray_Descr* descr = PyArray_DESCR((PyArrayObject*)obj);
// descr->kind == 'M' for datetime objects
// descr->elsize == 8 for 64bit
// ??? is the [M] / [D] resolution for a numpy array of datetime64 objects?
I found this previous post on converting scalar datetime64 objects Conversion of Numpy datetime64 in C API . But for my use case it is also valid to pass an empty array that has one of these types such as np.array([], dtype=np.dtype('datetime64[D]')), which means converting an element to a scalar to figure out the resolution information may not be possible.
Does anyone know what struct field I should be looking into or what functions I can use in the numpy C API to figure out this resolution information?