|
58 | 58 | CategoricalDtype,
|
59 | 59 | ExtensionDtype,
|
60 | 60 | PandasDtype,
|
| 61 | + PeriodDtype, |
61 | 62 | )
|
62 | 63 | from pandas.core.dtypes.generic import (
|
63 | 64 | ABCDataFrame,
|
@@ -1728,6 +1729,12 @@ class NDArrayBackedExtensionBlock(libinternals.NDArrayBackedBlock, EABackedBlock
|
1728 | 1729 |
|
1729 | 1730 | values: NDArrayBackedExtensionArray
|
1730 | 1731 |
|
| 1732 | + # error: Signature of "is_extension" incompatible with supertype "Block" |
| 1733 | + @cache_readonly |
| 1734 | + def is_extension(self) -> bool: # type: ignore[override] |
| 1735 | + # i.e. datetime64tz, PeriodDtype |
| 1736 | + return not isinstance(self.dtype, np.dtype) |
| 1737 | + |
1731 | 1738 | @property
|
1732 | 1739 | def is_view(self) -> bool:
|
1733 | 1740 | """return a boolean if I am possibly a view"""
|
@@ -1756,6 +1763,9 @@ def where(self, other, cond) -> list[Block]:
|
1756 | 1763 | try:
|
1757 | 1764 | res_values = arr.T._where(cond, other).T
|
1758 | 1765 | except (ValueError, TypeError):
|
| 1766 | + if isinstance(self.dtype, PeriodDtype): |
| 1767 | + # TODO: don't special-case |
| 1768 | + raise |
1759 | 1769 | blk = self.coerce_to_target_dtype(other)
|
1760 | 1770 | nbs = blk.where(other, cond)
|
1761 | 1771 | return self._maybe_downcast(nbs, "infer")
|
@@ -1949,6 +1959,8 @@ def get_block_type(dtype: DtypeObj):
|
1949 | 1959 | cls = CategoricalBlock
|
1950 | 1960 | elif vtype is Timestamp:
|
1951 | 1961 | cls = DatetimeTZBlock
|
| 1962 | + elif isinstance(dtype, PeriodDtype): |
| 1963 | + cls = NDArrayBackedExtensionBlock |
1952 | 1964 | elif isinstance(dtype, ExtensionDtype):
|
1953 | 1965 | # Note: need to be sure PandasArray is unwrapped before we get here
|
1954 | 1966 | cls = ExtensionBlock
|
|
0 commit comments