@@ -130,99 +130,125 @@ def test_datetime64_fillna(self):
130130 def test_datetime64_tz_fillna (self ):
131131 for tz in ['US/Eastern' , 'Asia/Tokyo' ]:
132132 # DatetimeBlock
133- s = Series ([Timestamp ('2011-01-01 10:00' ), pd .NaT , Timestamp (
134- '2011-01-03 10:00' ), pd .NaT ])
133+ s = Series ([Timestamp ('2011-01-01 10:00' ), pd .NaT ,
134+ Timestamp ('2011-01-03 10:00' ), pd .NaT ])
135+ null_loc = pd .Series ([False , True , False , True ])
136+
135137 result = s .fillna (pd .Timestamp ('2011-01-02 10:00' ))
136- expected = Series ([Timestamp ('2011-01-01 10:00' ), Timestamp (
137- '2011-01-02 10:00' ), Timestamp ('2011-01-03 10:00' ), Timestamp (
138- '2011-01-02 10:00' )])
138+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
139+ Timestamp ('2011-01-02 10:00' ),
140+ Timestamp ('2011-01-03 10:00' ),
141+ Timestamp ('2011-01-02 10:00' )])
139142 self .assert_series_equal (expected , result )
143+ # check s is not changed
144+ self .assert_series_equal (pd .isnull (s ), null_loc )
140145
141146 result = s .fillna (pd .Timestamp ('2011-01-02 10:00' , tz = tz ))
142- expected = Series ([Timestamp ('2011-01-01 10:00' ), Timestamp (
143- '2011-01-02 10:00' , tz = tz ), Timestamp ('2011-01-03 10:00' ),
144- Timestamp ('2011-01-02 10:00' , tz = tz )])
147+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
148+ Timestamp ('2011-01-02 10:00' , tz = tz ),
149+ Timestamp ('2011-01-03 10:00' ),
150+ Timestamp ('2011-01-02 10:00' , tz = tz )])
145151 self .assert_series_equal (expected , result )
152+ self .assert_series_equal (pd .isnull (s ), null_loc )
146153
147154 result = s .fillna ('AAA' )
148155 expected = Series ([Timestamp ('2011-01-01 10:00' ), 'AAA' ,
149156 Timestamp ('2011-01-03 10:00' ), 'AAA' ],
150157 dtype = object )
151158 self .assert_series_equal (expected , result )
159+ self .assert_series_equal (pd .isnull (s ), null_loc )
152160
153161 result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
154162 3 : pd .Timestamp ('2011-01-04 10:00' )})
155- expected = Series ([Timestamp ('2011-01-01 10:00' ), Timestamp (
156- '2011-01-02 10:00' , tz = tz ), Timestamp ('2011-01-03 10:00' ),
157- Timestamp ('2011-01-04 10:00' )])
163+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
164+ Timestamp ('2011-01-02 10:00' , tz = tz ),
165+ Timestamp ('2011-01-03 10:00' ),
166+ Timestamp ('2011-01-04 10:00' )])
158167 self .assert_series_equal (expected , result )
168+ self .assert_series_equal (pd .isnull (s ), null_loc )
159169
160170 result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' ),
161171 3 : pd .Timestamp ('2011-01-04 10:00' )})
162- expected = Series ([Timestamp ('2011-01-01 10:00' ), Timestamp (
163- '2011-01-02 10:00' ), Timestamp ('2011-01-03 10:00' ), Timestamp (
164- '2011-01-04 10:00' )])
172+ expected = Series ([Timestamp ('2011-01-01 10:00' ),
173+ Timestamp ('2011-01-02 10:00' ),
174+ Timestamp ('2011-01-03 10:00' ),
175+ Timestamp ('2011-01-04 10:00' )])
165176 self .assert_series_equal (expected , result )
177+ self .assert_series_equal (pd .isnull (s ), null_loc )
166178
167179 # DatetimeBlockTZ
168180 idx = pd .DatetimeIndex (['2011-01-01 10:00' , pd .NaT ,
169181 '2011-01-03 10:00' , pd .NaT ], tz = tz )
170182 s = pd .Series (idx )
183+ self .assertEqual (s .dtype , 'datetime64[ns, {0}]' .format (tz ))
184+ self .assert_series_equal (pd .isnull (s ), null_loc )
185+
171186 result = s .fillna (pd .Timestamp ('2011-01-02 10:00' ))
172- expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), Timestamp (
173- '2011-01-02 10:00' ), Timestamp ('2011-01-03 10:00' , tz = tz ),
174- Timestamp ('2011-01-02 10:00' )])
187+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
188+ Timestamp ('2011-01-02 10:00' ),
189+ Timestamp ('2011-01-03 10:00' , tz = tz ),
190+ Timestamp ('2011-01-02 10:00' )])
175191 self .assert_series_equal (expected , result )
192+ self .assert_series_equal (pd .isnull (s ), null_loc )
176193
177194 result = s .fillna (pd .Timestamp ('2011-01-02 10:00' , tz = tz ))
178195 idx = pd .DatetimeIndex (['2011-01-01 10:00' , '2011-01-02 10:00' ,
179196 '2011-01-03 10:00' , '2011-01-02 10:00' ],
180197 tz = tz )
181198 expected = Series (idx )
182199 self .assert_series_equal (expected , result )
200+ self .assert_series_equal (pd .isnull (s ), null_loc )
183201
184- result = s .fillna (pd .Timestamp (
185- '2011-01-02 10:00' , tz = tz ).to_pydatetime ())
202+ result = s .fillna (pd .Timestamp ('2011-01-02 10:00' ,
203+ tz = tz ).to_pydatetime ())
186204 idx = pd .DatetimeIndex (['2011-01-01 10:00' , '2011-01-02 10:00' ,
187205 '2011-01-03 10:00' , '2011-01-02 10:00' ],
188206 tz = tz )
189207 expected = Series (idx )
190208 self .assert_series_equal (expected , result )
209+ self .assert_series_equal (pd .isnull (s ), null_loc )
191210
192211 result = s .fillna ('AAA' )
193212 expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), 'AAA' ,
194213 Timestamp ('2011-01-03 10:00' , tz = tz ), 'AAA' ],
195214 dtype = object )
196215 self .assert_series_equal (expected , result )
216+ self .assert_series_equal (pd .isnull (s ), null_loc )
197217
198218 result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
199219 3 : pd .Timestamp ('2011-01-04 10:00' )})
200- expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), Timestamp (
201- '2011-01-02 10:00' , tz = tz ), Timestamp (
202- '2011-01-03 10:00' , tz = tz ), Timestamp ('2011-01-04 10:00' )])
220+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
221+ Timestamp ('2011-01-02 10:00' , tz = tz ),
222+ Timestamp ('2011-01-03 10:00' , tz = tz ),
223+ Timestamp ('2011-01-04 10:00' )])
203224 self .assert_series_equal (expected , result )
225+ self .assert_series_equal (pd .isnull (s ), null_loc )
204226
205227 result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
206228 3 : pd .Timestamp ('2011-01-04 10:00' , tz = tz )})
207- expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), Timestamp (
208- '2011-01-02 10:00' , tz = tz ), Timestamp (
209- '2011-01-03 10:00' , tz = tz ), Timestamp ( '2011-01-04 10:00' ,
210- tz = tz )])
229+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
230+ Timestamp ( '2011-01-02 10:00' , tz = tz ),
231+ Timestamp ( '2011-01-03 10:00' , tz = tz ),
232+ Timestamp ( '2011-01-04 10:00' , tz = tz )])
211233 self .assert_series_equal (expected , result )
234+ self .assert_series_equal (pd .isnull (s ), null_loc )
212235
213236 # filling with a naive/other zone, coerce to object
214237 result = s .fillna (Timestamp ('20130101' ))
215- expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), Timestamp (
216- '2013-01-01' ), Timestamp ('2011-01-03 10:00' , tz = tz ), Timestamp (
217- '2013-01-01' )])
238+ expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
239+ Timestamp ('2013-01-01' ),
240+ Timestamp ('2011-01-03 10:00' , tz = tz ),
241+ Timestamp ('2013-01-01' )])
218242 self .assert_series_equal (expected , result )
243+ self .assert_series_equal (pd .isnull (s ), null_loc )
219244
220245 result = s .fillna (Timestamp ('20130101' , tz = 'US/Pacific' ))
221246 expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
222247 Timestamp ('2013-01-01' , tz = 'US/Pacific' ),
223248 Timestamp ('2011-01-03 10:00' , tz = tz ),
224249 Timestamp ('2013-01-01' , tz = 'US/Pacific' )])
225250 self .assert_series_equal (expected , result )
251+ self .assert_series_equal (pd .isnull (s ), null_loc )
226252
227253 def test_fillna_int (self ):
228254 s = Series (np .random .randint (- 100 , 100 , 50 ))
0 commit comments