|
6 | 6 | import numbers
|
7 | 7 | import warnings
|
8 | 8 | from collections.abc import Callable, Hashable, Mapping, Sequence
|
9 |
| -from datetime import timedelta |
10 | 9 | from functools import partial
|
11 | 10 | from types import EllipsisType
|
12 | 11 | from typing import TYPE_CHECKING, Any, NoReturn, cast
|
@@ -232,10 +231,16 @@ def _as_nanosecond_precision(data):
|
232 | 231 |
|
233 | 232 | def _possibly_convert_objects(values):
|
234 | 233 | """Convert arrays of datetime.datetime and datetime.timedelta objects into
|
235 |
| - datetime64 and timedelta64, according to the pandas convention. For the time |
236 |
| - being, convert any non-nanosecond precision DatetimeIndex or TimedeltaIndex |
237 |
| - objects to nanosecond precision. While pandas is relaxing this in version |
238 |
| - 2.0.0, in xarray we will need to make sure we are ready to handle |
| 234 | + datetime64 and timedelta64, according to the pandas convention. |
| 235 | +
|
| 236 | + * datetime.datetime |
| 237 | + * datetime.timedelta |
| 238 | + * pd.Timestamp |
| 239 | + * pd.Timedelta |
| 240 | +
|
| 241 | + For the time being, convert any non-nanosecond precision DatetimeIndex or |
| 242 | + TimedeltaIndex objects to nanosecond precision. While pandas is relaxing this |
| 243 | + in version 2.0.0, in xarray we will need to make sure we are ready to handle |
239 | 244 | non-nanosecond precision datetimes or timedeltas in our code before allowing
|
240 | 245 | such values to pass through unchanged. Converting to nanosecond precision
|
241 | 246 | through pandas.Series objects ensures that datetimes and timedeltas are
|
@@ -305,13 +310,6 @@ def convert_non_numpy_type(data):
|
305 | 310 | if isinstance(data, tuple):
|
306 | 311 | data = utils.to_0d_object_array(data)
|
307 | 312 |
|
308 |
| - if isinstance(data, pd.Timestamp): |
309 |
| - # TODO: convert, handle datetime objects, too |
310 |
| - data = np.datetime64(data.value, "ns") |
311 |
| - |
312 |
| - if isinstance(data, timedelta): |
313 |
| - data = np.timedelta64(getattr(data, "value", data), "ns") |
314 |
| - |
315 | 313 | # we don't want nested self-described arrays
|
316 | 314 | if isinstance(data, pd.Series | pd.DataFrame):
|
317 | 315 | pandas_data = data.values
|
|
0 commit comments