4

I can't see how to reveal the units for numpy.datetime64. Say:

t=np.datetime64(123456789, 'ms' )

What's the method to tell me the units are 'ms'?

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
Quant
  • 4,253
  • 3
  • 17
  • 15

2 Answers2

6

As of NumPy 1.14 (Jan 2018), the datetime_data function is available to return a tuple of (units, number of base units in step) for a given datetime64 dtype:

>>> dt = np.datetime64(123456789, 'ns')
>>> np.datetime_data(dt)
('ns', 1)
>>> dt_units = np.datetime)data(dt)[0]
>>> print(dt_units)
'ns'
Isaiah Norton
  • 4,205
  • 1
  • 24
  • 38
1

You can query using:

np.dtype(t)
#dtype('<M8[ms]')

from where you can see the units in ms.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234