|
21 | 21 | _NS_DTYPE, _TD_DTYPE, ensure_platform_int, is_bool_dtype, is_categorical,
|
22 | 22 | is_categorical_dtype, is_datetime64_dtype, is_datetime64tz_dtype,
|
23 | 23 | is_dtype_equal, is_extension_array_dtype, is_extension_type,
|
24 |
| - is_float_dtype, is_integer, is_integer_dtype, is_list_like, |
25 |
| - is_numeric_v_string_like, is_object_dtype, is_re, is_re_compilable, |
26 |
| - is_sparse, is_timedelta64_dtype, pandas_dtype) |
| 24 | + is_float_dtype, is_integer, is_integer_dtype, is_interval_dtype, |
| 25 | + is_list_like, is_numeric_v_string_like, is_object_dtype, is_period_dtype, |
| 26 | + is_re, is_re_compilable, is_sparse, is_timedelta64_dtype, pandas_dtype) |
27 | 27 | import pandas.core.dtypes.concat as _concat
|
28 | 28 | from pandas.core.dtypes.dtypes import (
|
29 | 29 | CategoricalDtype, DatetimeTZDtype, ExtensionDtype, PandasExtensionDtype)
|
@@ -1996,6 +1996,18 @@ def _unstack(self, unstacker_func, new_columns, n_rows, fill_value):
|
1996 | 1996 | return blocks, mask
|
1997 | 1997 |
|
1998 | 1998 |
|
| 1999 | +class ObjectValuesExtensionBlock(ExtensionBlock): |
| 2000 | + """ |
| 2001 | + Block providing backwards-compatibility for `.values`. |
| 2002 | +
|
| 2003 | + Used by PeriodArray and IntervalArray to ensure that |
| 2004 | + Series[T].values is an ndarray of objects. |
| 2005 | + """ |
| 2006 | + |
| 2007 | + def external_values(self, dtype=None): |
| 2008 | + return self.values.astype(object) |
| 2009 | + |
| 2010 | + |
1999 | 2011 | class NumericBlock(Block):
|
2000 | 2012 | __slots__ = ()
|
2001 | 2013 | is_numeric = True
|
@@ -3017,6 +3029,8 @@ def get_block_type(values, dtype=None):
|
3017 | 3029 |
|
3018 | 3030 | if is_categorical(values):
|
3019 | 3031 | cls = CategoricalBlock
|
| 3032 | + elif is_interval_dtype(dtype) or is_period_dtype(dtype): |
| 3033 | + cls = ObjectValuesExtensionBlock |
3020 | 3034 | elif is_extension_array_dtype(values):
|
3021 | 3035 | cls = ExtensionBlock
|
3022 | 3036 | elif issubclass(vtype, np.floating):
|
|
0 commit comments