@@ -3937,6 +3937,89 @@ def test_datetime64_fillna(self):
39373937 result = s .fillna (method = 'backfill' )
39383938 assert_series_equal (result , expected )
39393939
3940+ def test_datetime64_tz_fillna (self ):
3941+ for tz in ['US/Eastern' , 'Asia/Tokyo' ]:
3942+ # DatetimeBlock
3943+ s = Series ([Timestamp ('2011-01-01 10:00' ), pd .NaT ,
3944+ Timestamp ('2011-01-03 10:00' ), pd .NaT ])
3945+ result = s .fillna (pd .Timestamp ('2011-01-02 10:00' ))
3946+ expected = Series ([Timestamp ('2011-01-01 10:00' ), Timestamp ('2011-01-02 10:00' ),
3947+ Timestamp ('2011-01-03 10:00' ), Timestamp ('2011-01-02 10:00' )])
3948+ self .assert_series_equal (expected , result )
3949+
3950+ result = s .fillna (pd .Timestamp ('2011-01-02 10:00' , tz = tz ))
3951+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
3952+ Timestamp ('2011-01-02 10:00' , tz = tz ),
3953+ Timestamp ('2011-01-03 10:00' ),
3954+ Timestamp ('2011-01-02 10:00' , tz = tz )])
3955+ self .assert_series_equal (expected , result )
3956+
3957+ result = s .fillna ('AAA' )
3958+ expected = Series ([Timestamp ('2011-01-01 10:00' ), 'AAA' ,
3959+ Timestamp ('2011-01-03 10:00' ), 'AAA' ], dtype = object )
3960+ self .assert_series_equal (expected , result )
3961+
3962+ result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
3963+ 3 : pd .Timestamp ('2011-01-04 10:00' )})
3964+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
3965+ Timestamp ('2011-01-02 10:00' , tz = tz ),
3966+ Timestamp ('2011-01-03 10:00' ),
3967+ Timestamp ('2011-01-04 10:00' )])
3968+ self .assert_series_equal (expected , result )
3969+
3970+ result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' ),
3971+ 3 : pd .Timestamp ('2011-01-04 10:00' )})
3972+ expected = Series ([Timestamp ('2011-01-01 10:00' ), Timestamp ('2011-01-02 10:00' ),
3973+ Timestamp ('2011-01-03 10:00' ), Timestamp ('2011-01-04 10:00' )])
3974+ self .assert_series_equal (expected , result )
3975+
3976+ # DatetimeBlockTZ
3977+ idx = pd .DatetimeIndex (['2011-01-01 10:00' , pd .NaT ,
3978+ '2011-01-03 10:00' , pd .NaT ], tz = tz )
3979+ s = pd .Series (idx )
3980+ result = s .fillna (pd .Timestamp ('2011-01-02 10:00' ))
3981+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
3982+ Timestamp ('2011-01-02 10:00' ),
3983+ Timestamp ('2011-01-03 10:00' , tz = tz ),
3984+ Timestamp ('2011-01-02 10:00' )])
3985+ self .assert_series_equal (expected , result )
3986+
3987+ result = s .fillna (pd .Timestamp ('2011-01-02 10:00' , tz = tz ))
3988+ idx = pd .DatetimeIndex (['2011-01-01 10:00' , '2011-01-02 10:00' ,
3989+ '2011-01-03 10:00' , '2011-01-02 10:00' ],
3990+ tz = tz )
3991+ expected = Series (idx )
3992+ self .assert_series_equal (expected , result )
3993+
3994+ result = s .fillna (pd .Timestamp ('2011-01-02 10:00' , tz = tz ).to_pydatetime ())
3995+ idx = pd .DatetimeIndex (['2011-01-01 10:00' , '2011-01-02 10:00' ,
3996+ '2011-01-03 10:00' , '2011-01-02 10:00' ],
3997+ tz = tz )
3998+ expected = Series (idx )
3999+ self .assert_series_equal (expected , result )
4000+
4001+ result = s .fillna ('AAA' )
4002+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), 'AAA' ,
4003+ Timestamp ('2011-01-03 10:00' , tz = tz ), 'AAA' ],
4004+ dtype = object )
4005+ self .assert_series_equal (expected , result )
4006+
4007+ result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
4008+ 3 : pd .Timestamp ('2011-01-04 10:00' )})
4009+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
4010+ Timestamp ('2011-01-02 10:00' , tz = tz ),
4011+ Timestamp ('2011-01-03 10:00' , tz = tz ),
4012+ Timestamp ('2011-01-04 10:00' )])
4013+ self .assert_series_equal (expected , result )
4014+
4015+ result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
4016+ 3 : pd .Timestamp ('2011-01-04 10:00' , tz = tz )})
4017+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
4018+ Timestamp ('2011-01-02 10:00' , tz = tz ),
4019+ Timestamp ('2011-01-03 10:00' , tz = tz ),
4020+ Timestamp ('2011-01-04 10:00' , tz = tz )])
4021+ self .assert_series_equal (expected , result )
4022+
39404023 def test_fillna_int (self ):
39414024 s = Series (np .random .randint (- 100 , 100 , 50 ))
39424025 s .fillna (method = 'ffill' , inplace = True )
@@ -5022,6 +5105,29 @@ def test_dropna_empty(self):
50225105 # invalid axis
50235106 self .assertRaises (ValueError , s .dropna , axis = 1 )
50245107
5108+
5109+ def test_datetime64_tz_dropna (self ):
5110+ # DatetimeBlock
5111+ s = Series ([Timestamp ('2011-01-01 10:00' ), pd .NaT ,
5112+ Timestamp ('2011-01-03 10:00' ), pd .NaT ])
5113+ result = s .dropna ()
5114+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
5115+ Timestamp ('2011-01-03 10:00' )], index = [0 , 2 ])
5116+ self .assert_series_equal (result , expected )
5117+
5118+ # DatetimeBlockTZ
5119+ idx = pd .DatetimeIndex (['2011-01-01 10:00' , pd .NaT ,
5120+ '2011-01-03 10:00' , pd .NaT ],
5121+ tz = 'Asia/Tokyo' )
5122+ s = pd .Series (idx )
5123+ self .assertEqual (s .dtype , 'datetime64[ns, Asia/Tokyo]' )
5124+ result = s .dropna ()
5125+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
5126+ Timestamp ('2011-01-03 10:00' , tz = 'Asia/Tokyo' )],
5127+ index = [0 , 2 ])
5128+ self .assertEqual (result .dtype , 'datetime64[ns, Asia/Tokyo]' )
5129+ self .assert_series_equal (result , expected )
5130+
50255131 def test_axis_alias (self ):
50265132 s = Series ([1 , 2 , np .nan ])
50275133 assert_series_equal (s .dropna (axis = 'rows' ), s .dropna (axis = 'index' ))
0 commit comments