@@ -419,12 +419,24 @@ def __arrow_array__(self, type=None):
419
419
"year" ,
420
420
"""
421
421
The year of the period.
422
+
423
+ Examples
424
+ --------
425
+ >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
426
+ >>> idx.year
427
+ Index([2023, 2024, 2025], dtype='int64')
422
428
""" ,
423
429
)
424
430
month = _field_accessor (
425
431
"month" ,
426
432
"""
427
433
The month as January=1, December=12.
434
+
435
+ Examples
436
+ --------
437
+ >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
438
+ >>> idx.month
439
+ Index([1, 2, 3], dtype='int64')
428
440
""" ,
429
441
)
430
442
day = _field_accessor (
@@ -449,25 +461,51 @@ def __arrow_array__(self, type=None):
449
461
"minute" ,
450
462
"""
451
463
The minute of the period.
464
+
465
+ Examples
466
+ --------
467
+ >>> idx = pd.PeriodIndex(["2023-01-01 10:30:00",
468
+ ... "2023-01-01 11:50:00"], freq='min')
469
+ >>> idx.minute
470
+ Index([30, 50], dtype='int64')
452
471
""" ,
453
472
)
454
473
second = _field_accessor (
455
474
"second" ,
456
475
"""
457
476
The second of the period.
477
+
478
+ Examples
479
+ --------
480
+ >>> idx = pd.PeriodIndex(["2023-01-01 10:00:30",
481
+ ... "2023-01-01 10:00:31"], freq='s')
482
+ >>> idx.second
483
+ Index([30, 31], dtype='int64')
458
484
""" ,
459
485
)
460
486
weekofyear = _field_accessor (
461
487
"week" ,
462
488
"""
463
489
The week ordinal of the year.
490
+
491
+ Examples
492
+ --------
493
+ >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
494
+ >>> idx.week # It can be written `weekofyear`
495
+ Index([5, 9, 13], dtype='int64')
464
496
""" ,
465
497
)
466
498
week = weekofyear
467
499
day_of_week = _field_accessor (
468
500
"day_of_week" ,
469
501
"""
470
502
The day of the week with Monday=0, Sunday=6.
503
+
504
+ Examples
505
+ --------
506
+ >>> idx = pd.PeriodIndex(["2023-01-01", "2023-01-02", "2023-01-03"], freq="D")
507
+ >>> idx.weekday
508
+ Index([6, 0, 1], dtype='int64')
471
509
""" ,
472
510
)
473
511
dayofweek = day_of_week
@@ -482,6 +520,12 @@ def __arrow_array__(self, type=None):
482
520
"quarter" ,
483
521
"""
484
522
The quarter of the date.
523
+
524
+ Examples
525
+ --------
526
+ >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
527
+ >>> idx.quarter
528
+ Index([1, 1, 1], dtype='int64')
485
529
""" ,
486
530
)
487
531
qyear = _field_accessor ("qyear" )
@@ -512,6 +556,12 @@ def __arrow_array__(self, type=None):
512
556
def is_leap_year (self ) -> npt .NDArray [np .bool_ ]:
513
557
"""
514
558
Logical indicating if the date belongs to a leap year.
559
+
560
+ Examples
561
+ --------
562
+ >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
563
+ >>> idx.is_leap_year
564
+ array([False, True, False])
515
565
"""
516
566
return isleapyear_arr (np .asarray (self .year ))
517
567
@@ -530,6 +580,13 @@ def to_timestamp(self, freq=None, how: str = "start") -> DatetimeArray:
530
580
Returns
531
581
-------
532
582
DatetimeArray/Index
583
+
584
+ Examples
585
+ --------
586
+ >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
587
+ >>> idx.to_timestamp()
588
+ DatetimeIndex(['2023-01-01', '2023-02-01', '2023-03-01'],
589
+ dtype='datetime64[ns]', freq='MS')
533
590
"""
534
591
from pandas .core .arrays import DatetimeArray
535
592
0 commit comments