Skip to content

Commit 99bafdd

Browse files
committed
Update type for PeriodDtype
Removed unused IntervalDtypeType
1 parent a277e4a commit 99bafdd

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

Diff for: pandas/core/dtypes/common.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from pandas.compat import (string_types, text_type, binary_type,
55
PY3, PY36)
66
from pandas._libs import algos, lib
7-
from pandas._libs.tslibs import conversion
7+
from pandas._libs.tslibs import conversion, Period
8+
from pandas._libs.interval import Interval
89

910
from pandas.core.dtypes.dtypes import (
1011
registry, CategoricalDtype, CategoricalDtypeType, DatetimeTZDtype,
11-
DatetimeTZDtypeType, PeriodDtype, PeriodDtypeType, IntervalDtype,
12-
IntervalDtypeType, PandasExtensionDtype, ExtensionDtype,
12+
DatetimeTZDtypeType, PeriodDtype, IntervalDtype,
13+
PandasExtensionDtype, ExtensionDtype,
1314
_pandas_registry)
1415
from pandas.core.dtypes.generic import (
1516
ABCCategorical, ABCPeriodIndex, ABCDatetimeIndex, ABCSeries,
@@ -1907,18 +1908,18 @@ def _get_dtype_type(arr_or_dtype):
19071908
elif isinstance(arr_or_dtype, DatetimeTZDtype):
19081909
return DatetimeTZDtypeType
19091910
elif isinstance(arr_or_dtype, IntervalDtype):
1910-
return IntervalDtypeType
1911+
return Interval
19111912
elif isinstance(arr_or_dtype, PeriodDtype):
1912-
return PeriodDtypeType
1913+
return Period
19131914
elif isinstance(arr_or_dtype, string_types):
19141915
if is_categorical_dtype(arr_or_dtype):
19151916
return CategoricalDtypeType
19161917
elif is_datetime64tz_dtype(arr_or_dtype):
19171918
return DatetimeTZDtypeType
19181919
elif is_period_dtype(arr_or_dtype):
1919-
return PeriodDtypeType
1920+
return Period
19201921
elif is_interval_dtype(arr_or_dtype):
1921-
return IntervalDtypeType
1922+
return Interval
19221923
return _get_dtype_type(np.dtype(arr_or_dtype))
19231924
try:
19241925
return arr_or_dtype.dtype.type

Diff for: pandas/core/dtypes/dtypes.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from pandas import compat
66
from pandas.core.dtypes.generic import ABCIndexClass, ABCCategoricalIndex
7+
from pandas._libs.tslibs import Period, NaT
78

89
from .base import ExtensionDtype, _DtypeOpsMixin
910

@@ -583,20 +584,13 @@ def __eq__(self, other):
583584
str(self.tz) == str(other.tz))
584585

585586

586-
class PeriodDtypeType(type):
587-
"""
588-
the type of PeriodDtype, this metaclass determines subclass ability
589-
"""
590-
pass
591-
592-
593587
class PeriodDtype(PandasExtensionDtype):
594588
"""
595589
A Period duck-typed class, suitable for holding a period with freq dtype.
596590
597591
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.int64.
598592
"""
599-
type = PeriodDtypeType
593+
type = Period
600594
kind = 'O'
601595
str = '|O08'
602596
base = np.dtype('O')
@@ -666,11 +660,15 @@ def construct_from_string(cls, string):
666660
raise TypeError("could not construct PeriodDtype")
667661

668662
def __unicode__(self):
669-
return "period[{freq}]".format(freq=self.freq.freqstr)
663+
return self.name
670664

671665
@property
672666
def name(self):
673-
return str(self)
667+
return u"period[{freq}]".format(freq=self.freq.freqstr)
668+
669+
@property
670+
def na_value(self):
671+
return NaT
674672

675673
def __hash__(self):
676674
# make myself hashable
@@ -705,13 +703,6 @@ def is_dtype(cls, dtype):
705703
return super(PeriodDtype, cls).is_dtype(dtype)
706704

707705

708-
class IntervalDtypeType(type):
709-
"""
710-
the type of IntervalDtype, this metaclass determines subclass ability
711-
"""
712-
pass
713-
714-
715706
@register_extension_dtype
716707
class IntervalDtype(PandasExtensionDtype, ExtensionDtype):
717708
"""

Diff for: pandas/tests/dtypes/test_common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,9 @@ def test__get_dtype_fails(input_param):
611611
('datetime64[ns, Europe/London]', com.DatetimeTZDtypeType),
612612
(pd.SparseSeries([1, 2], dtype='int32'), np.int32),
613613
(pd.SparseSeries([1, 2], dtype='int32').dtype, np.int32),
614-
(PeriodDtype(freq='D'), com.PeriodDtypeType),
615-
('period[D]', com.PeriodDtypeType),
616-
(IntervalDtype(), com.IntervalDtypeType),
614+
(PeriodDtype(freq='D'), pd.Period),
615+
('period[D]', pd.Period),
616+
(IntervalDtype(), pd.Interval),
617617
(None, type(None)),
618618
(1, type(None)),
619619
(1.2, type(None)),

0 commit comments

Comments
 (0)