Skip to content

Commit a410357

Browse files
committed
Remove the array_to_datetime function
1 parent d64c795 commit a410357

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

pygmt/clib/conversion.py

-83
Original file line numberDiff line numberDiff line change
@@ -320,86 +320,3 @@ def strings_to_ctypes_array(strings: Sequence[str] | np.ndarray) -> ctp.Array:
320320
['first', 'second', 'third']
321321
"""
322322
return (ctp.c_char_p * len(strings))(*[s.encode() for s in strings])
323-
324-
325-
def _array_to_datetime(array: Sequence[Any] | np.ndarray) -> np.ndarray:
326-
"""
327-
Convert a 1-D datetime array from various types into numpy.datetime64.
328-
329-
If the input array is not in legal datetime formats, raise a ValueError exception.
330-
331-
.. deprecated:: 0.14.0
332-
333-
The function is no longer used in the PyGMT project, but we keep this function
334-
to docuemnt and test the supported datetime types.
335-
336-
Parameters
337-
----------
338-
array
339-
The input datetime array in various formats.
340-
341-
Supported types:
342-
343-
- str
344-
- numpy.datetime64
345-
- pandas.DateTimeIndex
346-
- datetime.datetime and datetime.date
347-
348-
Returns
349-
-------
350-
array
351-
1-D datetime array in numpy.datetime64.
352-
353-
Raises
354-
------
355-
ValueError
356-
If the datetime string is invalid.
357-
358-
Examples
359-
--------
360-
>>> import datetime
361-
>>> # numpy.datetime64 array
362-
>>> x = np.array(
363-
... ["2010-06-01", "2011-06-01T12", "2012-01-01T12:34:56"],
364-
... dtype="datetime64[ns]",
365-
... )
366-
>>> _array_to_datetime(x)
367-
array(['2010-06-01T00:00:00.000000000', '2011-06-01T12:00:00.000000000',
368-
'2012-01-01T12:34:56.000000000'], dtype='datetime64[ns]')
369-
370-
>>> # pandas.DateTimeIndex array
371-
>>> import pandas as pd
372-
>>> x = pd.date_range("2013", freq="YS", periods=3)
373-
>>> _array_to_datetime(x)
374-
array(['2013-01-01T00:00:00.000000000', '2014-01-01T00:00:00.000000000',
375-
'2015-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
376-
377-
>>> # Python's built-in date and datetime
378-
>>> x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 1, 1)]
379-
>>> _array_to_datetime(x)
380-
array(['2018-01-01T00:00:00.000000', '2019-01-01T00:00:00.000000'],
381-
dtype='datetime64[us]')
382-
383-
>>> # Raw datetime strings in various format
384-
>>> x = [
385-
... "2018",
386-
... "2018-02",
387-
... "2018-03-01",
388-
... "2018-04-01T01:02:03",
389-
... ]
390-
>>> _array_to_datetime(x)
391-
array(['2018-01-01T00:00:00', '2018-02-01T00:00:00',
392-
'2018-03-01T00:00:00', '2018-04-01T01:02:03'],
393-
dtype='datetime64[s]')
394-
395-
>>> # Mixed datetime types
396-
>>> x = [
397-
... "2018-01-01",
398-
... np.datetime64("2018-01-01"),
399-
... datetime.datetime(2018, 1, 1),
400-
... ]
401-
>>> _array_to_datetime(x)
402-
array(['2018-01-01T00:00:00.000000', '2018-01-01T00:00:00.000000',
403-
'2018-01-01T00:00:00.000000'], dtype='datetime64[us]')
404-
"""
405-
return np.asarray(array, dtype=np.datetime64)

0 commit comments

Comments
 (0)