@@ -201,7 +201,14 @@ def func(intvidx_self, other, sort=False):
201
201
)
202
202
@accessor .delegate_names (
203
203
delegate = IntervalArray ,
204
- accessors = ["__array__" , "overlaps" , "contains" , "__len__" , "set_closed" ],
204
+ accessors = [
205
+ "__array__" ,
206
+ "overlaps" ,
207
+ "contains" ,
208
+ "__len__" ,
209
+ "set_closed" ,
210
+ "to_tuples" ,
211
+ ],
205
212
typ = "method" ,
206
213
overwrite = True ,
207
214
)
@@ -393,25 +400,6 @@ def __contains__(self, key) -> bool:
393
400
except KeyError :
394
401
return False
395
402
396
- @Appender (
397
- _interval_shared_docs ["to_tuples" ]
398
- % dict (
399
- return_type = "Index" ,
400
- examples = """
401
- Examples
402
- --------
403
- >>> idx = pd.IntervalIndex.from_arrays([0, np.nan, 2], [1, np.nan, 3])
404
- >>> idx.to_tuples()
405
- Index([(0.0, 1.0), (nan, nan), (2.0, 3.0)], dtype='object')
406
- >>> idx.to_tuples(na_tuple=False)
407
- Index([(0.0, 1.0), nan, (2.0, 3.0)], dtype='object')
408
- """ ,
409
- )
410
- )
411
- def to_tuples (self , na_tuple = True ):
412
- tuples = self ._data .to_tuples (na_tuple = na_tuple )
413
- return Index (tuples )
414
-
415
403
@cache_readonly
416
404
def _multiindex (self ):
417
405
return MultiIndex .from_arrays ([self .left , self .right ], names = ["left" , "right" ])
@@ -1004,8 +992,7 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
1004
992
result = self ._data .take (
1005
993
indices , axis = axis , allow_fill = allow_fill , fill_value = fill_value , ** kwargs
1006
994
)
1007
- attributes = self ._get_attributes_dict ()
1008
- return self ._simple_new (result , ** attributes )
995
+ return self ._shallow_copy (result )
1009
996
1010
997
def __getitem__ (self , value ):
1011
998
result = self ._data [value ]
@@ -1206,7 +1193,9 @@ def _delegate_method(self, name, *args, **kwargs):
1206
1193
res = method (* args , ** kwargs )
1207
1194
if is_scalar (res ) or name in self ._raw_inherit :
1208
1195
return res
1209
- return type (self )(res , name = self .name )
1196
+ if isinstance (res , IntervalArray ):
1197
+ return type (self )._simple_new (res , name = self .name )
1198
+ return Index (res )
1210
1199
1211
1200
1212
1201
IntervalIndex ._add_logical_methods_disabled ()
0 commit comments