4
4
5
5
import numpy as np
6
6
7
+ from pandas .compat import add_metaclass , _WritableDoc
7
8
from pandas .core .dtypes .missing import isna
8
9
from pandas .core .dtypes .cast import find_common_type
9
10
from pandas .core .dtypes .common import (
@@ -130,13 +131,12 @@ def _new_IntervalIndex(cls, d):
130
131
""" ),
131
132
132
133
))
134
+ @add_metaclass (_WritableDoc )
133
135
class IntervalIndex (IntervalMixin , Index ):
134
136
_typ = 'intervalindex'
135
137
_comparables = ['name' ]
136
138
_attributes = ['name' , 'closed' ]
137
139
_allow_index_ops = True
138
- _exception_rewrite = lambda : rewrite_exception ('IntervalArray' ,
139
- 'IntervalIndex' )
140
140
141
141
# we would like our indexing holder to defer to us
142
142
_defer_to_indexing = True
@@ -153,7 +153,7 @@ def __new__(cls, data, closed=None, dtype=None, copy=False,
153
153
if name is None and hasattr (data , 'name' ):
154
154
name = data .name
155
155
156
- with cls ._exception_rewrite ( ):
156
+ with rewrite_exception ( "IntervalArray" , cls .__name__ ):
157
157
array = IntervalArray (data , closed = closed , copy = copy , dtype = dtype ,
158
158
fastpath = fastpath ,
159
159
verify_integrity = verify_integrity )
@@ -274,7 +274,7 @@ def from_intervals(cls, data, closed=None, name=None, copy=False,
274
274
msg = ('IntervalIndex.from_intervals is deprecated and will be '
275
275
'removed in a future version; Use IntervalIndex(...) instead' )
276
276
warnings .warn (msg , FutureWarning , stacklevel = 2 )
277
- with cls ._exception_rewrite ( ):
277
+ with rewrite_exception ( "IntervalArray" , cls .__name__ ):
278
278
array = IntervalArray (data , closed = closed , copy = copy , dtype = dtype )
279
279
280
280
if name is None and isinstance (data , cls ):
@@ -286,7 +286,7 @@ def from_intervals(cls, data, closed=None, name=None, copy=False,
286
286
@Appender (_interval_shared_docs ['from_tuples' ] % _index_doc_kwargs )
287
287
def from_tuples (cls , data , closed = 'right' , name = None , copy = False ,
288
288
dtype = None ):
289
- with cls ._exception_rewrite ( ):
289
+ with rewrite_exception ( "IntervalArray" , cls .__name__ ):
290
290
arr = IntervalArray .from_tuples (data , closed = closed , copy = copy ,
291
291
dtype = dtype )
292
292
return cls ._simple_new (arr , name = name )
0 commit comments