5
5
6
6
import pandas as pd
7
7
import pandas .util .testing as tm
8
- import pandas .util ._test_decorators as td
9
8
import pandas .compat as compat
10
9
11
10
@@ -1195,38 +1194,33 @@ def test_fillna_index_period(self):
1195
1194
pass
1196
1195
1197
1196
1198
- @pytest .mark .parametrize ('how' , ['dict' , 'series' ])
1199
- @pytest .mark .parametrize ('to_key' , [
1200
- 'object' , 'int64' , 'float64' , 'complex128' , 'bool' , 'datetime64[ns]' ,
1201
- 'datetime64[ns, UTC]' , 'datetime64[ns, US/Eastern]' , 'timedelta64[ns]' ])
1202
- @pytest .mark .parametrize ('from_key' , [
1203
- 'object' , 'int64' , 'float64' , 'complex128' , 'bool' , 'datetime64[ns]' ,
1204
- 'datetime64[ns, UTC]' , 'datetime64[ns, US/Eastern]' , 'timedelta64[ns]' ])
1205
- class TestReplaceSeriesCoercion (object ):
1206
-
1207
- rep = {}
1208
- rep ['object' ] = ['a' , 'b' ]
1209
- rep ['int64' ] = [4 , 5 ]
1210
- rep ['float64' ] = [1.1 , 2.2 ]
1211
- rep ['complex128' ] = [1 + 1j , 2 + 2j ]
1212
- rep ['bool' ] = [True , False ]
1213
- rep ['datetime64[ns]' ] = [pd .Timestamp ('2011-01-01' ),
1214
- pd .Timestamp ('2011-01-03' )]
1215
-
1216
- for tz in ['UTC' , 'US/Eastern' ]:
1217
- # to test tz => different tz replacement
1218
- key = 'datetime64[ns, {0}]' .format (tz )
1219
- rep [key ] = [pd .Timestamp ('2011-01-01' , tz = tz ),
1220
- pd .Timestamp ('2011-01-03' , tz = tz )]
1221
-
1222
- rep ['timedelta64[ns]' ] = [pd .Timedelta ('1 day' ),
1223
- pd .Timedelta ('2 day' )]
1224
-
1225
- def test_replace_series (self , how , to_key , from_key ):
1226
- if from_key == 'bool' and how == 'series' and compat .PY3 :
1227
- # doesn't work in PY3, though ...dict_from_bool works fine
1228
- pytest .skip ("doesn't work as in PY3" )
1197
+ class TestReplaceSeriesCoercion (CoercionBase ):
1229
1198
1199
+ # not indexing, but place here for consisntency
1200
+
1201
+ klasses = ['series' ]
1202
+ method = 'replace'
1203
+
1204
+ def setup_method (self , method ):
1205
+ self .rep = {}
1206
+ self .rep ['object' ] = ['a' , 'b' ]
1207
+ self .rep ['int64' ] = [4 , 5 ]
1208
+ self .rep ['float64' ] = [1.1 , 2.2 ]
1209
+ self .rep ['complex128' ] = [1 + 1j , 2 + 2j ]
1210
+ self .rep ['bool' ] = [True , False ]
1211
+ self .rep ['datetime64[ns]' ] = [pd .Timestamp ('2011-01-01' ),
1212
+ pd .Timestamp ('2011-01-03' )]
1213
+
1214
+ for tz in ['UTC' , 'US/Eastern' ]:
1215
+ # to test tz => different tz replacement
1216
+ key = 'datetime64[ns, {0}]' .format (tz )
1217
+ self .rep [key ] = [pd .Timestamp ('2011-01-01' , tz = tz ),
1218
+ pd .Timestamp ('2011-01-03' , tz = tz )]
1219
+
1220
+ self .rep ['timedelta64[ns]' ] = [pd .Timedelta ('1 day' ),
1221
+ pd .Timedelta ('2 day' )]
1222
+
1223
+ def _assert_replace_conversion (self , from_key , to_key , how ):
1230
1224
index = pd .Index ([3 , 4 ], name = 'xxx' )
1231
1225
obj = pd .Series (self .rep [from_key ], index = index , name = 'yyy' )
1232
1226
assert obj .dtype == from_key
@@ -1248,8 +1242,10 @@ def test_replace_series(self, how, to_key, from_key):
1248
1242
(from_key == 'complex128' and
1249
1243
to_key in ('int64' , 'float64' ))):
1250
1244
1251
- td .skip_if_32bit ()
1252
- td .skip_if_windows ()
1245
+ # buggy on 32-bit / window
1246
+ if compat .is_platform_32bit () or compat .is_platform_windows ():
1247
+ pytest .skip ("32-bit platform buggy: {0} -> {1}" .format
1248
+ (from_key , to_key ))
1253
1249
1254
1250
# Expected: do not downcast by replacement
1255
1251
exp = pd .Series (self .rep [to_key ], index = index ,
@@ -1260,3 +1256,78 @@ def test_replace_series(self, how, to_key, from_key):
1260
1256
assert exp .dtype == to_key
1261
1257
1262
1258
tm .assert_series_equal (result , exp )
1259
+
1260
+ def test_replace_series_object (self ):
1261
+ from_key = 'object'
1262
+ for to_key in self .rep :
1263
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1264
+
1265
+ for to_key in self .rep :
1266
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1267
+
1268
+ def test_replace_series_int64 (self ):
1269
+ from_key = 'int64'
1270
+ for to_key in self .rep :
1271
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1272
+
1273
+ for to_key in self .rep :
1274
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1275
+
1276
+ def test_replace_series_float64 (self ):
1277
+ from_key = 'float64'
1278
+ for to_key in self .rep :
1279
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1280
+
1281
+ for to_key in self .rep :
1282
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1283
+
1284
+ def test_replace_series_complex128 (self ):
1285
+ from_key = 'complex128'
1286
+ for to_key in self .rep :
1287
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1288
+
1289
+ for to_key in self .rep :
1290
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1291
+
1292
+ def test_replace_series_bool (self ):
1293
+ from_key = 'bool'
1294
+ for to_key in self .rep :
1295
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1296
+
1297
+ for to_key in self .rep :
1298
+
1299
+ if compat .PY3 :
1300
+ # doesn't work in PY3, though ...dict_from_bool works fine
1301
+ pytest .skip ("doesn't work as in PY3" )
1302
+
1303
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1304
+
1305
+ def test_replace_series_datetime64 (self ):
1306
+ from_key = 'datetime64[ns]'
1307
+ for to_key in self .rep :
1308
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1309
+
1310
+ from_key = 'datetime64[ns]'
1311
+ for to_key in self .rep :
1312
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1313
+
1314
+ def test_replace_series_datetime64tz (self ):
1315
+ from_key = 'datetime64[ns, US/Eastern]'
1316
+ for to_key in self .rep :
1317
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1318
+
1319
+ from_key = 'datetime64[ns, US/Eastern]'
1320
+ for to_key in self .rep :
1321
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1322
+
1323
+ def test_replace_series_timedelta64 (self ):
1324
+ from_key = 'timedelta64[ns]'
1325
+ for to_key in self .rep :
1326
+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1327
+
1328
+ from_key = 'timedelta64[ns]'
1329
+ for to_key in self .rep :
1330
+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
1331
+
1332
+ def test_replace_series_period (self ):
1333
+ pass
0 commit comments