@@ -130,99 +130,125 @@ def test_datetime64_fillna(self):
130
130
def test_datetime64_tz_fillna (self ):
131
131
for tz in ['US/Eastern' , 'Asia/Tokyo' ]:
132
132
# 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
+
135
137
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' )])
139
142
self .assert_series_equal (expected , result )
143
+ # check s is not changed
144
+ self .assert_series_equal (pd .isnull (s ), null_loc )
140
145
141
146
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 )])
145
151
self .assert_series_equal (expected , result )
152
+ self .assert_series_equal (pd .isnull (s ), null_loc )
146
153
147
154
result = s .fillna ('AAA' )
148
155
expected = Series ([Timestamp ('2011-01-01 10:00' ), 'AAA' ,
149
156
Timestamp ('2011-01-03 10:00' ), 'AAA' ],
150
157
dtype = object )
151
158
self .assert_series_equal (expected , result )
159
+ self .assert_series_equal (pd .isnull (s ), null_loc )
152
160
153
161
result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
154
162
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' )])
158
167
self .assert_series_equal (expected , result )
168
+ self .assert_series_equal (pd .isnull (s ), null_loc )
159
169
160
170
result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' ),
161
171
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' )])
165
176
self .assert_series_equal (expected , result )
177
+ self .assert_series_equal (pd .isnull (s ), null_loc )
166
178
167
179
# DatetimeBlockTZ
168
180
idx = pd .DatetimeIndex (['2011-01-01 10:00' , pd .NaT ,
169
181
'2011-01-03 10:00' , pd .NaT ], tz = tz )
170
182
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
+
171
186
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' )])
175
191
self .assert_series_equal (expected , result )
192
+ self .assert_series_equal (pd .isnull (s ), null_loc )
176
193
177
194
result = s .fillna (pd .Timestamp ('2011-01-02 10:00' , tz = tz ))
178
195
idx = pd .DatetimeIndex (['2011-01-01 10:00' , '2011-01-02 10:00' ,
179
196
'2011-01-03 10:00' , '2011-01-02 10:00' ],
180
197
tz = tz )
181
198
expected = Series (idx )
182
199
self .assert_series_equal (expected , result )
200
+ self .assert_series_equal (pd .isnull (s ), null_loc )
183
201
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 ())
186
204
idx = pd .DatetimeIndex (['2011-01-01 10:00' , '2011-01-02 10:00' ,
187
205
'2011-01-03 10:00' , '2011-01-02 10:00' ],
188
206
tz = tz )
189
207
expected = Series (idx )
190
208
self .assert_series_equal (expected , result )
209
+ self .assert_series_equal (pd .isnull (s ), null_loc )
191
210
192
211
result = s .fillna ('AAA' )
193
212
expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ), 'AAA' ,
194
213
Timestamp ('2011-01-03 10:00' , tz = tz ), 'AAA' ],
195
214
dtype = object )
196
215
self .assert_series_equal (expected , result )
216
+ self .assert_series_equal (pd .isnull (s ), null_loc )
197
217
198
218
result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
199
219
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' )])
203
224
self .assert_series_equal (expected , result )
225
+ self .assert_series_equal (pd .isnull (s ), null_loc )
204
226
205
227
result = s .fillna ({1 : pd .Timestamp ('2011-01-02 10:00' , tz = tz ),
206
228
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 )])
211
233
self .assert_series_equal (expected , result )
234
+ self .assert_series_equal (pd .isnull (s ), null_loc )
212
235
213
236
# filling with a naive/other zone, coerce to object
214
237
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' )])
218
242
self .assert_series_equal (expected , result )
243
+ self .assert_series_equal (pd .isnull (s ), null_loc )
219
244
220
245
result = s .fillna (Timestamp ('20130101' , tz = 'US/Pacific' ))
221
246
expected = Series ([Timestamp ('2011-01-01 10:00' , tz = tz ),
222
247
Timestamp ('2013-01-01' , tz = 'US/Pacific' ),
223
248
Timestamp ('2011-01-03 10:00' , tz = tz ),
224
249
Timestamp ('2013-01-01' , tz = 'US/Pacific' )])
225
250
self .assert_series_equal (expected , result )
251
+ self .assert_series_equal (pd .isnull (s ), null_loc )
226
252
227
253
def test_fillna_int (self ):
228
254
s = Series (np .random .randint (- 100 , 100 , 50 ))
0 commit comments