@@ -457,7 +457,7 @@ def from_breaks(cls, breaks, closed='right', name=None, copy=False,
457
457
def from_arrays (cls , left , right , closed = 'right' , name = None , copy = False ,
458
458
dtype = None ):
459
459
"""
460
- Construct an IntervalIndex from a a left and right array
460
+ Construct from two arrays defining the left and right bounds.
461
461
462
462
Parameters
463
463
----------
@@ -471,11 +471,38 @@ def from_arrays(cls, left, right, closed='right', name=None, copy=False,
471
471
name : object, optional
472
472
Name to be stored in the index.
473
473
copy : boolean, default False
474
- copy the data
475
- dtype : dtype or None, default None
476
- If None, dtype will be inferred
474
+ Copy the data.
475
+ dtype : dtype, optional
476
+ If None, dtype will be inferred.
477
477
478
- ..versionadded:: 0.23.0
478
+ .. versionadded:: 0.23.0
479
+
480
+ Returns
481
+ -------
482
+ index : IntervalIndex
483
+
484
+ Notes
485
+ -----
486
+ Each element of `left` must be less than or equal to the `right`
487
+ element at the same position. If an element is missing, it must be
488
+ missing in both `left` and `right`. A TypeError is raised when
489
+ using an unsupported type for `left` or `right`. At the moment,
490
+ 'category', 'object', and 'string' subtypes are not supported.
491
+
492
+ Raises
493
+ ------
494
+ ValueError
495
+ When a value is missing in only one of `left` or `right`.
496
+ When a value in `left` is greater than the corresponding value
497
+ in `right`.
498
+
499
+ See Also
500
+ --------
501
+ interval_range : Function to create a fixed frequency IntervalIndex.
502
+ IntervalIndex.from_breaks : Construct an IntervalIndex from an array of
503
+ splits.
504
+ IntervalIndex.from_tuples : Construct an IntervalIndex from a
505
+ list/array of tuples.
479
506
480
507
Examples
481
508
--------
@@ -484,13 +511,29 @@ def from_arrays(cls, left, right, closed='right', name=None, copy=False,
484
511
closed='right',
485
512
dtype='interval[int64]')
486
513
487
- See Also
488
- --------
489
- interval_range : Function to create a fixed frequency IntervalIndex
490
- IntervalIndex.from_breaks : Construct an IntervalIndex from an array of
491
- splits
492
- IntervalIndex.from_tuples : Construct an IntervalIndex from a
493
- list/array of tuples
514
+ If you want to segment different groups of people based on
515
+ ages, you can apply the method as follows:
516
+
517
+ >>> ages = pd.IntervalIndex.from_arrays([0, 2, 13],
518
+ ... [2, 13, 19], closed='left')
519
+ >>> ages
520
+ IntervalIndex([[0, 2), [2, 13), [13, 19)]
521
+ closed='left',
522
+ dtype='interval[int64]')
523
+ >>> s = pd.Series(['baby', 'kid', 'teen'], ages)
524
+ >>> s
525
+ [0, 2) baby
526
+ [2, 13) kid
527
+ [13, 19) teen
528
+ dtype: object
529
+
530
+ Values may be missing, but they must be missing in both arrays.
531
+
532
+ >>> pd.IntervalIndex.from_arrays([0, np.nan, 13],
533
+ ... [2, np.nan, 19])
534
+ IntervalIndex([(0.0, 2.0], nan, (13.0, 19.0]]
535
+ closed='right',
536
+ dtype='interval[float64]')
494
537
"""
495
538
left = maybe_convert_platform_interval (left )
496
539
right = maybe_convert_platform_interval (right )
0 commit comments