45
45
46
46
47
47
def _new_DatetimeIndex (cls , d ):
48
- """ This is called upon unpickling, rather than the default which doesn't
49
- have arguments and breaks __new__ """
50
-
48
+ """
49
+ This is called upon unpickling, rather than the default which doesn't
50
+ have arguments and breaks __new__
51
+ """
51
52
if "data" in d and not isinstance (d ["data" ], DatetimeIndex ):
52
53
# Avoid need to verify integrity by calling simple_new directly
53
54
data = d .pop ("data" )
@@ -100,9 +101,9 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin):
100
101
101
102
Parameters
102
103
----------
103
- data : array-like (1-dimensional), optional
104
+ data : array-like (1-dimensional), optional
104
105
Optional datetime-like data to construct index with.
105
- copy : bool
106
+ copy : bool
106
107
Make a copy of input ndarray.
107
108
freq : str or pandas offset object, optional
108
109
One of pandas date offset strings or corresponding objects. The string
@@ -273,7 +274,7 @@ def __new__(
273
274
@classmethod
274
275
def _simple_new (cls , values , name = None , freq = None , tz = None , dtype = None ):
275
276
"""
276
- we require the we have a dtype compat for the values
277
+ We require the we have a dtype compat for the values
277
278
if we are passed a non-dtype compat, then coerce using the constructor
278
279
"""
279
280
if isinstance (values , DatetimeArray ):
@@ -345,7 +346,13 @@ def tz(self, value):
345
346
346
347
@cache_readonly
347
348
def _is_dates_only (self ) -> bool :
348
- """Return a boolean if we are only dates (and don't have a timezone)"""
349
+ """
350
+ Return a boolean if we are only dates (and don't have a timezone)
351
+
352
+ Returns
353
+ -------
354
+ bool
355
+ """
349
356
from pandas .io .formats .format import _is_dates_only
350
357
351
358
return _is_dates_only (self .values ) and self .tz is None
@@ -360,7 +367,9 @@ def __reduce__(self):
360
367
return _new_DatetimeIndex , (type (self ), d ), None
361
368
362
369
def __setstate__ (self , state ):
363
- """Necessary for making this object picklable"""
370
+ """
371
+ Necessary for making this object picklable.
372
+ """
364
373
if isinstance (state , dict ):
365
374
super ().__setstate__ (state )
366
375
@@ -393,7 +402,9 @@ def __setstate__(self, state):
393
402
_unpickle_compat = __setstate__
394
403
395
404
def _convert_for_op (self , value ):
396
- """ Convert value to be insertable to ndarray """
405
+ """
406
+ Convert value to be insertable to ndarray.
407
+ """
397
408
if self ._has_same_tz (value ):
398
409
return _to_M8 (value )
399
410
raise ValueError ("Passed item and index have different timezone" )
@@ -461,7 +472,7 @@ def _union(self, other, sort):
461
472
462
473
def union_many (self , others ):
463
474
"""
464
- A bit of a hack to accelerate unioning a collection of indexes
475
+ A bit of a hack to accelerate unioning a collection of indexes.
465
476
"""
466
477
this = self
467
478
@@ -489,7 +500,7 @@ def union_many(self, others):
489
500
this ._data ._dtype = dtype
490
501
return this
491
502
492
- def _can_fast_union (self , other ):
503
+ def _can_fast_union (self , other ) -> bool :
493
504
if not isinstance (other , DatetimeIndex ):
494
505
return False
495
506
@@ -581,7 +592,7 @@ def intersection(self, other, sort=False):
581
592
582
593
Returns
583
594
-------
584
- y : Index or DatetimeIndex or TimedeltaIndex
595
+ Index or DatetimeIndex or TimedeltaIndex
585
596
"""
586
597
return super ().intersection (other , sort = sort )
587
598
@@ -699,7 +710,9 @@ def snap(self, freq="S"):
699
710
# we know it conforms; skip check
700
711
return DatetimeIndex ._simple_new (snapped , name = self .name , tz = self .tz , freq = freq )
701
712
702
- def join (self , other , how = "left" , level = None , return_indexers = False , sort = False ):
713
+ def join (
714
+ self , other , how : str = "left" , level = None , return_indexers = False , sort = False
715
+ ):
703
716
"""
704
717
See Index.join
705
718
"""
@@ -840,9 +853,8 @@ def _parsed_string_to_bounds(self, reso, parsed):
840
853
if parsed .tzinfo is not None :
841
854
if self .tz is None :
842
855
raise ValueError (
843
- "The index must be timezone aware "
844
- "when indexing with a date string with a "
845
- "UTC offset"
856
+ "The index must be timezone aware when indexing "
857
+ "with a date string with a UTC offset"
846
858
)
847
859
start = start .tz_localize (parsed .tzinfo ).tz_convert (self .tz )
848
860
end = end .tz_localize (parsed .tzinfo ).tz_convert (self .tz )
@@ -851,7 +863,16 @@ def _parsed_string_to_bounds(self, reso, parsed):
851
863
end = end .tz_localize (self .tz )
852
864
return start , end
853
865
854
- def _partial_date_slice (self , reso , parsed , use_lhs = True , use_rhs = True ):
866
+ def _partial_date_slice (
867
+ self , reso : str , parsed , use_lhs : bool = True , use_rhs : bool = True
868
+ ):
869
+ """
870
+ Parameters
871
+ ----------
872
+ reso : str
873
+ use_lhs : bool, default True
874
+ use_rhs : bool, default True
875
+ """
855
876
is_monotonic = self .is_monotonic
856
877
if (
857
878
is_monotonic
0 commit comments