Skip to content

Commit ec2c7af

Browse files
committed
move null-handling methods back down to null-handling section
1 parent 695010c commit ec2c7af

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

pandas/core/arrays/datetimelike.py

+52-52
Original file line numberDiff line numberDiff line change
@@ -535,58 +535,6 @@ def _maybe_clear_freq(self):
535535
# DatetimeArray and TimedeltaArray
536536
pass
537537

538-
def isna(self):
539-
return self._isnan
540-
541-
@property # NB: override with cache_readonly in immutable subclasses
542-
def _isnan(self):
543-
"""
544-
return if each value is nan
545-
"""
546-
return (self.asi8 == iNaT)
547-
548-
@property # NB: override with cache_readonly in immutable subclasses
549-
def _hasnans(self):
550-
"""
551-
return if I have any nans; enables various perf speedups
552-
"""
553-
return bool(self._isnan.any())
554-
555-
def fillna(self, value=None, method=None, limit=None):
556-
# TODO(GH-20300): remove this
557-
# Just overriding to ensure that we avoid an astype(object).
558-
# Either 20300 or a `_values_for_fillna` would avoid this duplication.
559-
if isinstance(value, ABCSeries):
560-
value = value.array
561-
562-
value, method = validate_fillna_kwargs(value, method)
563-
564-
mask = self.isna()
565-
566-
if is_array_like(value):
567-
if len(value) != len(self):
568-
raise ValueError("Length of 'value' does not match. Got ({}) "
569-
" expected {}".format(len(value), len(self)))
570-
value = value[mask]
571-
572-
if mask.any():
573-
if method is not None:
574-
if method == 'pad':
575-
func = missing.pad_1d
576-
else:
577-
func = missing.backfill_1d
578-
579-
new_values = func(self._data, limit=limit,
580-
mask=mask)
581-
new_values = type(self)(new_values, dtype=self.dtype)
582-
else:
583-
# fill with value
584-
new_values = self.copy()
585-
new_values[mask] = value
586-
else:
587-
new_values = self.copy()
588-
return new_values
589-
590538
def astype(self, dtype, copy=True):
591539
# Some notes on cases we don't have to handle here in the base class:
592540
# 1. PeriodArray.astype handles period -> period
@@ -826,6 +774,58 @@ def _maybe_mask_results(self, result, fill_value=iNaT, convert=None):
826774
result[self._isnan] = fill_value
827775
return result
828776

777+
def isna(self):
778+
return self._isnan
779+
780+
@property # NB: override with cache_readonly in immutable subclasses
781+
def _isnan(self):
782+
"""
783+
return if each value is nan
784+
"""
785+
return (self.asi8 == iNaT)
786+
787+
@property # NB: override with cache_readonly in immutable subclasses
788+
def _hasnans(self):
789+
"""
790+
return if I have any nans; enables various perf speedups
791+
"""
792+
return bool(self._isnan.any())
793+
794+
def fillna(self, value=None, method=None, limit=None):
795+
# TODO(GH-20300): remove this
796+
# Just overriding to ensure that we avoid an astype(object).
797+
# Either 20300 or a `_values_for_fillna` would avoid this duplication.
798+
if isinstance(value, ABCSeries):
799+
value = value.array
800+
801+
value, method = validate_fillna_kwargs(value, method)
802+
803+
mask = self.isna()
804+
805+
if is_array_like(value):
806+
if len(value) != len(self):
807+
raise ValueError("Length of 'value' does not match. Got ({}) "
808+
" expected {}".format(len(value), len(self)))
809+
value = value[mask]
810+
811+
if mask.any():
812+
if method is not None:
813+
if method == 'pad':
814+
func = missing.pad_1d
815+
else:
816+
func = missing.backfill_1d
817+
818+
new_values = func(self._data, limit=limit,
819+
mask=mask)
820+
new_values = type(self)(new_values, dtype=self.dtype)
821+
else:
822+
# fill with value
823+
new_values = self.copy()
824+
new_values[mask] = value
825+
else:
826+
new_values = self.copy()
827+
return new_values
828+
829829
# ------------------------------------------------------------------
830830
# Frequency Properties/Methods
831831

0 commit comments

Comments
 (0)