4545
4646
4747def _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+ """
5152 if "data" in d and not isinstance (d ["data" ], DatetimeIndex ):
5253 # Avoid need to verify integrity by calling simple_new directly
5354 data = d .pop ("data" )
@@ -100,9 +101,9 @@ class DatetimeIndex(DatetimeIndexOpsMixin, Int64Index, DatetimeDelegateMixin):
100101
101102 Parameters
102103 ----------
103- data : array-like (1-dimensional), optional
104+ data : array-like (1-dimensional), optional
104105 Optional datetime-like data to construct index with.
105- copy : bool
106+ copy : bool
106107 Make a copy of input ndarray.
107108 freq : str or pandas offset object, optional
108109 One of pandas date offset strings or corresponding objects. The string
@@ -273,7 +274,7 @@ def __new__(
273274 @classmethod
274275 def _simple_new (cls , values , name = None , freq = None , tz = None , dtype = None ):
275276 """
276- we require the we have a dtype compat for the values
277+ We require the we have a dtype compat for the values
277278 if we are passed a non-dtype compat, then coerce using the constructor
278279 """
279280 if isinstance (values , DatetimeArray ):
@@ -345,7 +346,13 @@ def tz(self, value):
345346
346347 @cache_readonly
347348 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+ """
349356 from pandas .io .formats .format import _is_dates_only
350357
351358 return _is_dates_only (self .values ) and self .tz is None
@@ -360,7 +367,9 @@ def __reduce__(self):
360367 return _new_DatetimeIndex , (type (self ), d ), None
361368
362369 def __setstate__ (self , state ):
363- """Necessary for making this object picklable"""
370+ """
371+ Necessary for making this object picklable.
372+ """
364373 if isinstance (state , dict ):
365374 super ().__setstate__ (state )
366375
@@ -393,7 +402,9 @@ def __setstate__(self, state):
393402 _unpickle_compat = __setstate__
394403
395404 def _convert_for_op (self , value ):
396- """ Convert value to be insertable to ndarray """
405+ """
406+ Convert value to be insertable to ndarray.
407+ """
397408 if self ._has_same_tz (value ):
398409 return _to_M8 (value )
399410 raise ValueError ("Passed item and index have different timezone" )
@@ -461,7 +472,7 @@ def _union(self, other, sort):
461472
462473 def union_many (self , others ):
463474 """
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.
465476 """
466477 this = self
467478
@@ -489,7 +500,7 @@ def union_many(self, others):
489500 this ._data ._dtype = dtype
490501 return this
491502
492- def _can_fast_union (self , other ):
503+ def _can_fast_union (self , other ) -> bool :
493504 if not isinstance (other , DatetimeIndex ):
494505 return False
495506
@@ -581,7 +592,7 @@ def intersection(self, other, sort=False):
581592
582593 Returns
583594 -------
584- y : Index or DatetimeIndex or TimedeltaIndex
595+ Index or DatetimeIndex or TimedeltaIndex
585596 """
586597 return super ().intersection (other , sort = sort )
587598
@@ -699,7 +710,9 @@ def snap(self, freq="S"):
699710 # we know it conforms; skip check
700711 return DatetimeIndex ._simple_new (snapped , name = self .name , tz = self .tz , freq = freq )
701712
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+ ):
703716 """
704717 See Index.join
705718 """
@@ -840,9 +853,8 @@ def _parsed_string_to_bounds(self, reso, parsed):
840853 if parsed .tzinfo is not None :
841854 if self .tz is None :
842855 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"
846858 )
847859 start = start .tz_localize (parsed .tzinfo ).tz_convert (self .tz )
848860 end = end .tz_localize (parsed .tzinfo ).tz_convert (self .tz )
@@ -851,7 +863,16 @@ def _parsed_string_to_bounds(self, reso, parsed):
851863 end = end .tz_localize (self .tz )
852864 return start , end
853865
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+ """
855876 is_monotonic = self .is_monotonic
856877 if (
857878 is_monotonic
0 commit comments