@@ -456,24 +456,8 @@ def test_interval_index_arrays():
456
456
),
457
457
pd .IntervalIndex ,
458
458
)
459
- left_s_ts = pd .Series (
460
- [
461
- pd .Timestamp (2000 , 1 , 1 ),
462
- pd .Timestamp (2001 , 1 , 1 ),
463
- pd .Timestamp (2002 , 1 , 1 ),
464
- pd .Timestamp (2003 , 1 , 1 ),
465
- ],
466
- dtype = pd .Timestamp ,
467
- )
468
- right_s_ts = pd .Series (
469
- [
470
- pd .Timestamp (2001 , 1 , 1 ),
471
- pd .Timestamp (2002 , 1 , 1 ),
472
- pd .Timestamp (2003 , 1 , 1 ),
473
- pd .Timestamp (2004 , 1 , 1 ),
474
- ],
475
- dtype = pd .Timestamp ,
476
- )
459
+ left_s_ts = pd .Series (pd .date_range ("2000-01-01" , "2003-01-01" , freq = "Y" ))
460
+ right_s_ts = pd .Series (pd .date_range ("2001-01-01" , "2004-01-01" , freq = "Y" ))
477
461
check (
478
462
assert_type (
479
463
pd .IntervalIndex .from_arrays (left_s_ts , right_s_ts ),
@@ -504,9 +488,6 @@ def test_interval_index_arrays():
504
488
505
489
506
490
def test_interval_index_tuples ():
507
- int_arr : npt .NDArray [np .integer ] = np .array ([[1 , 2 ], [3 , 4 ]], dtype = np .int64 )
508
- float_arr : npt .NDArray [np .floating ] = np .array ([[1 , 2 ], [3 , 4 ]], dtype = np .float_ )
509
-
510
491
check (
511
492
assert_type (
512
493
pd .IntervalIndex .from_tuples ([(1 , 2 ), (2 , 3 )]),
@@ -516,33 +497,80 @@ def test_interval_index_tuples():
516
497
)
517
498
check (
518
499
assert_type (
519
- pd .IntervalIndex .from_tuples (int_arr ), "pd.IntervalIndex[pd.Interval[int]]"
500
+ pd .IntervalIndex .from_tuples ([(1.0 , 2.0 ), (2.0 , 3.0 )]),
501
+ "pd.IntervalIndex[pd.Interval[float]]" ,
520
502
),
521
503
pd .IntervalIndex ,
522
504
)
523
505
check (
524
506
assert_type (
525
- pd .IntervalIndex .from_tuples ([(1.0 , 2.0 ), (2.0 , 3.0 )]),
526
- "pd.IntervalIndex[pd.Interval[float]]" ,
507
+ pd .IntervalIndex .from_tuples (
508
+ [
509
+ (pd .Timestamp (2000 , 1 , 1 ), pd .Timestamp (2001 , 1 , 1 )),
510
+ (pd .Timestamp (2001 , 1 , 1 ), pd .Timestamp (2002 , 1 , 1 )),
511
+ ]
512
+ ),
513
+ "pd.IntervalIndex[pd.Interval[pd.Timestamp]]" ,
527
514
),
528
515
pd .IntervalIndex ,
529
516
)
530
517
check (
531
518
assert_type (
532
- pd .IntervalIndex .from_tuples (float_arr ),
533
- "pd.IntervalIndex[pd.Interval[float]]" ,
519
+ pd .IntervalIndex .from_tuples (
520
+ [
521
+ (dt .datetime (2000 , 1 , 1 ), dt .datetime (2001 , 1 , 1 )),
522
+ (dt .datetime (2001 , 1 , 1 ), dt .datetime (2002 , 1 , 1 )),
523
+ ]
524
+ ),
525
+ "pd.IntervalIndex[pd.Interval[pd.Timestamp]]" ,
534
526
),
535
527
pd .IntervalIndex ,
536
528
)
537
529
check (
538
530
assert_type (
539
531
pd .IntervalIndex .from_tuples (
540
532
[
541
- (pd . Timestamp ( 2000 , 1 , 1 ), pd . Timestamp ( 2001 , 1 , 1 )),
542
- (pd . Timestamp ( 2001 , 1 , 1 ), pd . Timestamp ( 2002 , 1 , 1 )),
533
+ (np . datetime64 ( " 2000-01-01" ), np . datetime64 ( " 2001-01-01" )),
534
+ (np . datetime64 ( " 2001-01-01" ), np . datetime64 ( " 2002-01-01" )),
543
535
]
544
536
),
545
537
"pd.IntervalIndex[pd.Interval[pd.Timestamp]]" ,
546
538
),
547
539
pd .IntervalIndex ,
548
540
)
541
+ check (
542
+ assert_type (
543
+ pd .IntervalIndex .from_tuples (
544
+ [
545
+ (pd .Timedelta (1 , "D" ), pd .Timedelta (2 , "D" )),
546
+ (pd .Timedelta (2 , "D" ), pd .Timedelta (3 , "D" )),
547
+ ]
548
+ ),
549
+ "pd.IntervalIndex[pd.Interval[pd.Timedelta]]" ,
550
+ ),
551
+ pd .IntervalIndex ,
552
+ )
553
+ check (
554
+ assert_type (
555
+ pd .IntervalIndex .from_tuples (
556
+ [
557
+ (dt .timedelta (days = 1 ), dt .timedelta (days = 2 )),
558
+ (dt .timedelta (days = 2 ), dt .timedelta (days = 3 )),
559
+ ]
560
+ ),
561
+ "pd.IntervalIndex[pd.Interval[pd.Timedelta]]" ,
562
+ ),
563
+ pd .IntervalIndex ,
564
+ )
565
+ check (
566
+ assert_type (
567
+ pd .IntervalIndex .from_tuples (
568
+ [
569
+ (np .timedelta64 (1 , "D" ), np .timedelta64 (2 , "D" )),
570
+ (np .timedelta64 (2 , "D" ), np .timedelta64 (3 , "D" )),
571
+ ]
572
+ ),
573
+ "pd.IntervalIndex[pd.Interval[pd.Timedelta]]" ,
574
+ ),
575
+ pd .IntervalIndex ,
576
+ )
0 commit comments