@@ -201,7 +201,14 @@ def func(intvidx_self, other, sort=False):
201201)
202202@accessor .delegate_names (
203203 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+ ],
205212 typ = "method" ,
206213 overwrite = True ,
207214)
@@ -393,25 +400,6 @@ def __contains__(self, key) -> bool:
393400 except KeyError :
394401 return False
395402
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-
415403 @cache_readonly
416404 def _multiindex (self ):
417405 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):
1004992 result = self ._data .take (
1005993 indices , axis = axis , allow_fill = allow_fill , fill_value = fill_value , ** kwargs
1006994 )
1007- attributes = self ._get_attributes_dict ()
1008- return self ._simple_new (result , ** attributes )
995+ return self ._shallow_copy (result )
1009996
1010997 def __getitem__ (self , value ):
1011998 result = self ._data [value ]
@@ -1206,7 +1193,9 @@ def _delegate_method(self, name, *args, **kwargs):
12061193 res = method (* args , ** kwargs )
12071194 if is_scalar (res ) or name in self ._raw_inherit :
12081195 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 )
12101199
12111200
12121201IntervalIndex ._add_logical_methods_disabled ()
0 commit comments