numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturns
datetime_as_string(arr, unit=None, timezone='naive', casting='same_kind')

Parameters

arr : array_like of datetime64

The array of UTC timestamps to format.

unit : str

One of None, 'auto', or a datetime unit <arrays.dtypes.dateunits> .

timezone : {'naive', 'UTC', 'local'} or tzinfo

Timezone information to use when displaying the datetime. If 'UTC', end with a Z to indicate UTC time. If 'local', convert to the local timezone first, and suffix with a +-#### timezone offset. If a tzinfo object, then do as with 'local', but use the specified timezone.

casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}

Casting to allow when changing between datetime units.

Returns

str_arr : ndarray

An array of strings the same shape as :None:None:`arr`.

Convert an array of datetimes into an array of strings.

Examples

This example is valid syntax, but we were not able to check execution
>>> import pytz
... d = np.arange('2002-10-27T04:30', 4*60, 60, dtype='M8[m]')
... d array(['2002-10-27T04:30', '2002-10-27T05:30', '2002-10-27T06:30', '2002-10-27T07:30'], dtype='datetime64[m]')

Setting the timezone to UTC shows the same information, but with a Z suffix

This example is valid syntax, but we were not able to check execution
>>> np.datetime_as_string(d, timezone='UTC')
array(['2002-10-27T04:30Z', '2002-10-27T05:30Z', '2002-10-27T06:30Z',
       '2002-10-27T07:30Z'], dtype='<U35')

Note that we picked datetimes that cross a DST boundary. Passing in a pytz timezone object will print the appropriate offset

This example is valid syntax, but we were not able to check execution
>>> np.datetime_as_string(d, timezone=pytz.timezone('US/Eastern'))
array(['2002-10-27T00:30-0400', '2002-10-27T01:30-0400',
       '2002-10-27T01:30-0500', '2002-10-27T02:30-0500'], dtype='<U39')

Passing in a unit will change the precision

This example is valid syntax, but we were not able to check execution
>>> np.datetime_as_string(d, unit='h')
array(['2002-10-27T04', '2002-10-27T05', '2002-10-27T06', '2002-10-27T07'],
      dtype='<U32')
This example is valid syntax, but we were not able to check execution
>>> np.datetime_as_string(d, unit='s')
array(['2002-10-27T04:30:00', '2002-10-27T05:30:00', '2002-10-27T06:30:00',
       '2002-10-27T07:30:00'], dtype='<U38')

'casting' can be used to specify whether precision can be changed

This example is valid syntax, but we were not able to check execution
>>> np.datetime_as_string(d, unit='h', casting='safe')
Traceback (most recent call last):
    ...
TypeError: Cannot create a datetime string as units 'h' from a NumPy
datetime with units 'm' according to the rule 'safe'
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : None#None
type: <class 'builtin_function_or_method'>
Commit: