|
14 | 14 | from pandas.util._decorators import Appender
|
15 | 15 |
|
16 | 16 | from pandas.core.dtypes.common import (
|
17 |
| - _INT64_DTYPE, _NS_DTYPE, is_datetime64_dtype, is_datetime64tz_dtype, |
18 |
| - is_extension_type, is_float_dtype, is_int64_dtype, is_object_dtype, |
19 |
| - is_period_dtype, is_string_dtype, is_timedelta64_dtype) |
| 17 | + _INT64_DTYPE, _NS_DTYPE, is_categorical_dtype, is_datetime64_dtype, |
| 18 | + is_datetime64tz_dtype, is_extension_type, is_float_dtype, is_int64_dtype, |
| 19 | + is_object_dtype, is_period_dtype, is_string_dtype, is_timedelta64_dtype) |
20 | 20 | from pandas.core.dtypes.dtypes import DatetimeTZDtype
|
21 | 21 | from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
|
22 | 22 | from pandas.core.dtypes.missing import isna
|
@@ -277,6 +277,8 @@ def _generate_range(cls, start, end, periods, freq, tz=None,
|
277 | 277 | if closed is not None:
|
278 | 278 | raise ValueError("Closed has to be None if not both of start"
|
279 | 279 | "and end are defined")
|
| 280 | + if start is NaT or end is NaT: |
| 281 | + raise ValueError("Neither `start` nor `end` can be NaT") |
280 | 282 |
|
281 | 283 | left_closed, right_closed = dtl.validate_endpoints(closed)
|
282 | 284 |
|
@@ -1666,6 +1668,13 @@ def maybe_convert_dtype(data, copy):
|
1666 | 1668 | raise TypeError("Passing PeriodDtype data is invalid. "
|
1667 | 1669 | "Use `data.to_timestamp()` instead")
|
1668 | 1670 |
|
| 1671 | + elif is_categorical_dtype(data): |
| 1672 | + # GH#18664 preserve tz in going DTI->Categorical->DTI |
| 1673 | + # TODO: cases where we need to do another pass through this func, |
| 1674 | + # e.g. the categories are timedelta64s |
| 1675 | + data = data.categories.take(data.codes, fill_value=NaT) |
| 1676 | + copy = False |
| 1677 | + |
1669 | 1678 | elif is_extension_type(data) and not is_datetime64tz_dtype(data):
|
1670 | 1679 | # Includes categorical
|
1671 | 1680 | # TODO: We have no tests for these
|
|
0 commit comments