@@ -535,58 +535,6 @@ def _maybe_clear_freq(self):
535
535
# DatetimeArray and TimedeltaArray
536
536
pass
537
537
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
-
590
538
def astype (self , dtype , copy = True ):
591
539
# Some notes on cases we don't have to handle here in the base class:
592
540
# 1. PeriodArray.astype handles period -> period
@@ -800,6 +748,23 @@ def map(self, mapper):
800
748
# ------------------------------------------------------------------
801
749
# Null Handling
802
750
751
+ def isna (self ):
752
+ return self ._isnan
753
+
754
+ @property # NB: override with cache_readonly in immutable subclasses
755
+ def _isnan (self ):
756
+ """
757
+ return if each value is nan
758
+ """
759
+ return (self .asi8 == iNaT )
760
+
761
+ @property # NB: override with cache_readonly in immutable subclasses
762
+ def _hasnans (self ):
763
+ """
764
+ return if I have any nans; enables various perf speedups
765
+ """
766
+ return bool (self ._isnan .any ())
767
+
803
768
def _maybe_mask_results (self , result , fill_value = iNaT , convert = None ):
804
769
"""
805
770
Parameters
@@ -826,6 +791,41 @@ def _maybe_mask_results(self, result, fill_value=iNaT, convert=None):
826
791
result [self ._isnan ] = fill_value
827
792
return result
828
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
+
829
829
# ------------------------------------------------------------------
830
830
# Frequency Properties/Methods
831
831
0 commit comments