Skip to content

Commit

Permalink
Update type for PeriodDtype
Browse files Browse the repository at this point in the history
Removed unused IntervalDtypeType
  • Loading branch information
TomAugspurger committed Oct 2, 2018
1 parent a277e4a commit 99bafdd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
15 changes: 8 additions & 7 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from pandas.compat import (string_types, text_type, binary_type,
PY3, PY36)
from pandas._libs import algos, lib
from pandas._libs.tslibs import conversion
from pandas._libs.tslibs import conversion, Period
from pandas._libs.interval import Interval

from pandas.core.dtypes.dtypes import (
registry, CategoricalDtype, CategoricalDtypeType, DatetimeTZDtype,
DatetimeTZDtypeType, PeriodDtype, PeriodDtypeType, IntervalDtype,
IntervalDtypeType, PandasExtensionDtype, ExtensionDtype,
DatetimeTZDtypeType, PeriodDtype, IntervalDtype,
PandasExtensionDtype, ExtensionDtype,
_pandas_registry)
from pandas.core.dtypes.generic import (
ABCCategorical, ABCPeriodIndex, ABCDatetimeIndex, ABCSeries,
Expand Down Expand Up @@ -1907,18 +1908,18 @@ def _get_dtype_type(arr_or_dtype):
elif isinstance(arr_or_dtype, DatetimeTZDtype):
return DatetimeTZDtypeType
elif isinstance(arr_or_dtype, IntervalDtype):
return IntervalDtypeType
return Interval
elif isinstance(arr_or_dtype, PeriodDtype):
return PeriodDtypeType
return Period
elif isinstance(arr_or_dtype, string_types):
if is_categorical_dtype(arr_or_dtype):
return CategoricalDtypeType
elif is_datetime64tz_dtype(arr_or_dtype):
return DatetimeTZDtypeType
elif is_period_dtype(arr_or_dtype):
return PeriodDtypeType
return Period
elif is_interval_dtype(arr_or_dtype):
return IntervalDtypeType
return Interval
return _get_dtype_type(np.dtype(arr_or_dtype))
try:
return arr_or_dtype.dtype.type
Expand Down
25 changes: 8 additions & 17 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from pandas import compat
from pandas.core.dtypes.generic import ABCIndexClass, ABCCategoricalIndex
from pandas._libs.tslibs import Period, NaT

from .base import ExtensionDtype, _DtypeOpsMixin

Expand Down Expand Up @@ -583,20 +584,13 @@ def __eq__(self, other):
str(self.tz) == str(other.tz))


class PeriodDtypeType(type):
"""
the type of PeriodDtype, this metaclass determines subclass ability
"""
pass


class PeriodDtype(PandasExtensionDtype):
"""
A Period duck-typed class, suitable for holding a period with freq dtype.
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.int64.
"""
type = PeriodDtypeType
type = Period
kind = 'O'
str = '|O08'
base = np.dtype('O')
Expand Down Expand Up @@ -666,11 +660,15 @@ def construct_from_string(cls, string):
raise TypeError("could not construct PeriodDtype")

def __unicode__(self):
return "period[{freq}]".format(freq=self.freq.freqstr)
return self.name

@property
def name(self):
return str(self)
return u"period[{freq}]".format(freq=self.freq.freqstr)

@property
def na_value(self):
return NaT

def __hash__(self):
# make myself hashable
Expand Down Expand Up @@ -705,13 +703,6 @@ def is_dtype(cls, dtype):
return super(PeriodDtype, cls).is_dtype(dtype)


class IntervalDtypeType(type):
"""
the type of IntervalDtype, this metaclass determines subclass ability
"""
pass


@register_extension_dtype
class IntervalDtype(PandasExtensionDtype, ExtensionDtype):
"""
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ def test__get_dtype_fails(input_param):
('datetime64[ns, Europe/London]', com.DatetimeTZDtypeType),
(pd.SparseSeries([1, 2], dtype='int32'), np.int32),
(pd.SparseSeries([1, 2], dtype='int32').dtype, np.int32),
(PeriodDtype(freq='D'), com.PeriodDtypeType),
('period[D]', com.PeriodDtypeType),
(IntervalDtype(), com.IntervalDtypeType),
(PeriodDtype(freq='D'), pd.Period),
('period[D]', pd.Period),
(IntervalDtype(), pd.Interval),
(None, type(None)),
(1, type(None)),
(1.2, type(None)),
Expand Down

0 comments on commit 99bafdd

Please sign in to comment.