Skip to content

Commit 82cc71d

Browse files
committed
remove code for unsupported dtypes and remove 'interval[]'
1 parent de7553b commit 82cc71d

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ Conversion
376376
- Bug in :class:`TimedeltaIndex` where division by a ``Series`` would return a ``TimedeltaIndex`` instead of a ``Series`` (issue:`19042`)
377377
- Bug in :class:`Series` with ``dtype='timedelta64[ns]`` where addition or subtraction of ``TimedeltaIndex`` could return a ``Series`` with an incorrect name (issue:`19043`)
378378
- Fixed bug where comparing :class:`DatetimeIndex` failed to raise ``TypeError`` when attempting to compare timezone-aware and timezone-naive datetimelike objects (:issue:`18162`)
379-
- Bug in ``IntervalDtype`` when constructing two instances with subtype ``CategoricalDtype`` where the second instance used cached attributes from the first (:issue:`18980`)
380379

381380
Indexing
382381
^^^^^^^^

pandas/core/dtypes/dtypes.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def __new__(cls, subtype=None):
654654
u.subtype = None
655655
return u
656656
elif (isinstance(subtype, compat.string_types) and
657-
subtype in ('interval', 'interval[]')):
657+
subtype.lower() == 'interval'):
658658
subtype = None
659659
else:
660660
if isinstance(subtype, compat.string_types):
@@ -667,27 +667,18 @@ def __new__(cls, subtype=None):
667667
except TypeError:
668668
raise ValueError("could not construct IntervalDtype")
669669

670-
if subtype is None:
671-
u = object.__new__(cls)
672-
u.subtype = None
673-
return u
674-
675670
if is_categorical_dtype(subtype) or is_string_dtype(subtype):
676671
# GH 19016
677672
msg = ('category, object, and string subtypes are not supported '
678673
'for IntervalDtype')
679674
raise TypeError(msg)
680675

681676
try:
682-
# GH 18980: need to combine since str and hash individually may not
683-
# be unique, e.g. str(CategoricalDtype) always returns 'category',
684-
# and hash(np.dtype('<m8')) == hash(np.dtype('<m8[ns]'))
685-
key = ''.join([str(subtype), str(hash(subtype))])
686-
return cls._cache[key]
677+
return cls._cache[str(subtype)]
687678
except KeyError:
688679
u = object.__new__(cls)
689680
u.subtype = subtype
690-
cls._cache[key] = u
681+
cls._cache[str(subtype)] = u
691682
return u
692683

693684
@classmethod
@@ -712,7 +703,7 @@ def __hash__(self):
712703

713704
def __eq__(self, other):
714705
if isinstance(other, compat.string_types):
715-
return other.title() in (self.name.title(), str(self).title())
706+
return other.lower() in (self.name.lower(), str(self).lower())
716707
elif not isinstance(other, IntervalDtype):
717708
return False
718709
elif self.subtype is None or other.subtype is None:

pandas/tests/dtypes/test_dtypes.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def test_construction(self, subtype):
458458
assert i.subtype == np.dtype('int64')
459459
assert is_interval_dtype(i)
460460

461-
@pytest.mark.parametrize('subtype', [None, 'interval', 'interval[]'])
461+
@pytest.mark.parametrize('subtype', [None, 'interval', 'Interval'])
462462
def test_construction_generic(self, subtype):
463463
# generic
464464
i = IntervalDtype(subtype)
@@ -535,25 +535,25 @@ def test_equality(self):
535535
IntervalDtype('float64'))
536536

537537
@pytest.mark.parametrize('subtype', [
538-
None, 'interval', 'interval[]', 'int64', 'uint64', 'float64', object,
539-
CategoricalDtype(), 'datetime64', 'timedelta64', PeriodDtype('Q')])
538+
None, 'interval', 'Interval', 'int64', 'uint64', 'float64',
539+
'complex128', 'datetime64', 'timedelta64', PeriodDtype('Q')])
540540
def test_equality_generic(self, subtype):
541541
# GH 18980
542542
dtype = IntervalDtype(subtype)
543543
assert is_dtype_equal(dtype, 'interval')
544544
assert is_dtype_equal(dtype, IntervalDtype())
545545

546546
@pytest.mark.parametrize('subtype', [
547-
'int64', 'uint64', 'float64', 'complex128', np.dtype('O'),
548-
CategoricalDtype(), 'datetime64', 'timedelta64', PeriodDtype('Q')])
547+
'int64', 'uint64', 'float64', 'complex128', 'datetime64',
548+
'timedelta64', PeriodDtype('Q')])
549549
def test_name_repr(self, subtype):
550550
# GH 18980
551551
dtype = IntervalDtype(subtype)
552552
expected = 'interval[{subtype}]'.format(subtype=subtype)
553553
assert str(dtype) == expected
554554
assert dtype.name == 'interval'
555555

556-
@pytest.mark.parametrize('subtype', [None, 'interval', 'interval[]'])
556+
@pytest.mark.parametrize('subtype', [None, 'interval', 'Interval'])
557557
def test_name_repr_generic(self, subtype):
558558
# GH 18980
559559
dtype = IntervalDtype(subtype)
@@ -600,15 +600,6 @@ def test_caching(self):
600600
tm.round_trip_pickle(dtype)
601601
assert len(IntervalDtype._cache) == 0
602602

603-
def test_caching_categoricaldtype(self):
604-
# GH 18980
605-
cdt1 = CategoricalDtype(list('abc'), True)
606-
cdt2 = CategoricalDtype(list('wxyz'), False)
607-
idt1 = IntervalDtype(cdt1)
608-
idt2 = IntervalDtype(cdt2)
609-
assert idt1.subtype is cdt1
610-
assert idt2.subtype is cdt2
611-
612603

613604
class TestCategoricalDtypeParametrized(object):
614605

0 commit comments

Comments
 (0)