File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 11"""Collection of utility functions used across the library."""
22import csv
3+ import datetime
34import os
45import string
56import random
@@ -907,4 +908,29 @@ def dict_to_ndarray(as_dict):
907908 columns = [as_dict [key ] for key in as_dict ]
908909 as_ndarray = np .column_stack (columns )
909910
910- return as_ndarray
911+ return as_ndarray
912+
913+
914+ def datetime64_to_datetime (dt64 ):
915+ """Convert a NumPy :class:`datetime64 <numpy:numpy.datetime64>` to a Python
916+ :class:`datetime <python:datetime.datetime>`.
917+
918+ :param dt64: The NumPy :class:`datetime64 <numpy:numpy.datetime64>` to convert.
919+ :type dt64: :class:`numpy.datetime64 <numpy:numpy.datetime64>`
920+
921+ :returns: A Python :class:`datetime <python:datetime.datetime>` instance.
922+ :rtype: :class:`datetime <python:datetime.datetime>`
923+
924+ :raises HighchartsDependencyError: if NumPy is not available in the runtime
925+ environment
926+
927+ """
928+ if not HAS_NUMPY :
929+ raise errors .HighchartsDependencyError ('NumPy is required for this feature. '
930+ 'It was not found in your runtime '
931+ 'environment. Please make sure it is '
932+ 'installed in your runtime '
933+ 'environment.' )
934+ timestamp = (dt64 - np .datetime64 ("1970-01-01T00:00:00" )) / np .timedelta64 (1 , "s" )
935+
936+ return datetime .datetime .fromtimestamp (timestamp , datetime .timezone .utc )
You can’t perform that action at this time.
0 commit comments