@@ -203,12 +203,6 @@ def create_mgr(descr, item_shape=None):
203
203
204
204
class TestBlock :
205
205
def setup_method (self , method ):
206
- # self.fblock = get_float_ex() # a,c,e
207
- # self.cblock = get_complex_ex() #
208
- # self.oblock = get_obj_ex()
209
- # self.bool_block = get_bool_ex()
210
- # self.int_block = get_int_ex()
211
-
212
206
self .fblock = create_block ("float" , [0 , 2 , 4 ])
213
207
self .cblock = create_block ("complex" , [7 ])
214
208
self .oblock = create_block ("object" , [1 , 3 ])
@@ -254,22 +248,11 @@ def test_merge(self):
254
248
tm .assert_numpy_array_equal (merged .values [[0 , 2 ]], np .array (avals ))
255
249
tm .assert_numpy_array_equal (merged .values [[1 , 3 ]], np .array (bvals ))
256
250
257
- # TODO: merge with mixed type?
258
-
259
251
def test_copy (self ):
260
252
cop = self .fblock .copy ()
261
253
assert cop is not self .fblock
262
254
assert_block_equal (self .fblock , cop )
263
255
264
- def test_reindex_index (self ):
265
- pass
266
-
267
- def test_reindex_cast (self ):
268
- pass
269
-
270
- def test_insert (self ):
271
- pass
272
-
273
256
def test_delete (self ):
274
257
newb = self .fblock .copy ()
275
258
newb .delete (0 )
@@ -300,39 +283,7 @@ def test_delete(self):
300
283
newb .delete (3 )
301
284
302
285
303
- class TestDatetimeBlock :
304
- def test_can_hold_element (self ):
305
- block = create_block ("datetime" , [0 ])
306
-
307
- # We will check that block._can_hold_element iff arr.__setitem__ works
308
- arr = pd .array (block .values .ravel ())
309
-
310
- # coerce None
311
- assert block ._can_hold_element (None )
312
- arr [0 ] = None
313
- assert arr [0 ] is pd .NaT
314
-
315
- # coerce different types of datetime objects
316
- vals = [np .datetime64 ("2010-10-10" ), datetime (2010 , 10 , 10 )]
317
- for val in vals :
318
- assert block ._can_hold_element (val )
319
- arr [0 ] = val
320
-
321
- val = date (2010 , 10 , 10 )
322
- assert not block ._can_hold_element (val )
323
-
324
- msg = (
325
- "'value' should be a 'Timestamp', 'NaT', "
326
- "or array of those. Got 'date' instead."
327
- )
328
- with pytest .raises (TypeError , match = msg ):
329
- arr [0 ] = val
330
-
331
-
332
286
class TestBlockManager :
333
- def test_constructor_corner (self ):
334
- pass
335
-
336
287
def test_attrs (self ):
337
288
mgr = create_mgr ("a,b,c: f8-1; d,e,f: f8-2" )
338
289
assert mgr .nblocks == 2
@@ -441,18 +392,6 @@ def test_set_change_dtype(self, mgr):
441
392
mgr2 .set ("quux" , tm .randn (N ))
442
393
assert mgr2 .get ("quux" ).dtype == np .float_
443
394
444
- def test_set_change_dtype_slice (self ): # GH8850
445
- cols = MultiIndex .from_tuples ([("1st" , "a" ), ("2nd" , "b" ), ("3rd" , "c" )])
446
- df = DataFrame ([[1.0 , 2 , 3 ], [4.0 , 5 , 6 ]], columns = cols )
447
- df ["2nd" ] = df ["2nd" ] * 2.0
448
-
449
- blocks = df ._to_dict_of_blocks ()
450
- assert sorted (blocks .keys ()) == ["float64" , "int64" ]
451
- tm .assert_frame_equal (
452
- blocks ["float64" ], DataFrame ([[1.0 , 4.0 ], [4.0 , 10.0 ]], columns = cols [:2 ])
453
- )
454
- tm .assert_frame_equal (blocks ["int64" ], DataFrame ([[3 ], [6 ]], columns = cols [2 :]))
455
-
456
395
def test_copy (self , mgr ):
457
396
cp = mgr .copy (deep = False )
458
397
for blk , cp_blk in zip (mgr .blocks , cp .blocks ):
@@ -486,7 +425,7 @@ def test_sparse_mixed(self):
486
425
assert len (mgr .blocks ) == 3
487
426
assert isinstance (mgr , BlockManager )
488
427
489
- # what to test here?
428
+ # TODO: what to test here?
490
429
491
430
def test_as_array_float (self ):
492
431
mgr = create_mgr ("c: f4; d: f2; e: f8" )
@@ -650,22 +589,6 @@ def test_interleave(self):
650
589
mgr = create_mgr ("a: M8[ns]; b: m8[ns]" )
651
590
assert mgr .as_array ().dtype == "object"
652
591
653
- def test_interleave_non_unique_cols (self ):
654
- df = DataFrame (
655
- [[pd .Timestamp ("20130101" ), 3.5 ], [pd .Timestamp ("20130102" ), 4.5 ]],
656
- columns = ["x" , "x" ],
657
- index = [1 , 2 ],
658
- )
659
-
660
- df_unique = df .copy ()
661
- df_unique .columns = ["x" , "y" ]
662
- assert df_unique .values .shape == df .values .shape
663
- tm .assert_numpy_array_equal (df_unique .values [0 ], df .values [0 ])
664
- tm .assert_numpy_array_equal (df_unique .values [1 ], df .values [1 ])
665
-
666
- def test_consolidate (self ):
667
- pass
668
-
669
592
def test_consolidate_ordering_issues (self , mgr ):
670
593
mgr .set ("f" , tm .randn (N ))
671
594
mgr .set ("d" , tm .randn (N ))
@@ -683,10 +606,6 @@ def test_consolidate_ordering_issues(self, mgr):
683
606
cons .blocks [0 ].mgr_locs .as_array , np .arange (len (cons .items ), dtype = np .int64 )
684
607
)
685
608
686
- def test_reindex_index (self ):
687
- # TODO: should this be pytest.skip?
688
- pass
689
-
690
609
def test_reindex_items (self ):
691
610
# mgr is not consolidated, f8 & f8-2 blocks
692
611
mgr = create_mgr ("a: f8; b: i8; c: f8; d: i8; e: f8; f: bool; g: f8-2" )
@@ -767,13 +686,6 @@ def test_get_bool_data(self):
767
686
def test_unicode_repr_doesnt_raise (self ):
768
687
repr (create_mgr ("b,\u05d0 : object" ))
769
688
770
- def test_missing_unicode_key (self ):
771
- df = DataFrame ({"a" : [1 ]})
772
- try :
773
- df .loc [:, "\u05d0 " ] # should not raise UnicodeEncodeError
774
- except KeyError :
775
- pass # this is the expected exception
776
-
777
689
def test_equals (self ):
778
690
# unique items
779
691
bm1 = create_mgr ("a,b,c: i8-1; d,e,f: i8-2" )
@@ -843,8 +755,6 @@ class TestIndexing:
843
755
create_mgr ("a,b: f8; c,d: i8; e,f: f8" , item_shape = (N , N )),
844
756
]
845
757
846
- # MANAGERS = [MANAGERS[6]]
847
-
848
758
@pytest .mark .parametrize ("mgr" , MANAGERS )
849
759
def test_get_slice (self , mgr ):
850
760
def assert_slice_ok (mgr , axis , slobj ):
@@ -994,11 +904,6 @@ def assert_reindex_indexer_is_ok(mgr, axis, new_labels, indexer, fill_value):
994
904
mgr , ax , pd .Index (["foo" , "bar" , "baz" ]), [0 , 1 , 2 ], fill_value ,
995
905
)
996
906
997
- # test_get_slice(slice_like, axis)
998
- # take(indexer, axis)
999
- # reindex_axis(new_labels, axis)
1000
- # reindex_indexer(new_labels, indexer, axis)
1001
-
1002
907
1003
908
class TestBlockPlacement :
1004
909
def test_slice_len (self ):
@@ -1151,6 +1056,33 @@ def any(self, axis=None):
1151
1056
1152
1057
1153
1058
class TestCanHoldElement :
1059
+ def test_datetime_block_can_hold_element (self ):
1060
+ block = create_block ("datetime" , [0 ])
1061
+
1062
+ # We will check that block._can_hold_element iff arr.__setitem__ works
1063
+ arr = pd .array (block .values .ravel ())
1064
+
1065
+ # coerce None
1066
+ assert block ._can_hold_element (None )
1067
+ arr [0 ] = None
1068
+ assert arr [0 ] is pd .NaT
1069
+
1070
+ # coerce different types of datetime objects
1071
+ vals = [np .datetime64 ("2010-10-10" ), datetime (2010 , 10 , 10 )]
1072
+ for val in vals :
1073
+ assert block ._can_hold_element (val )
1074
+ arr [0 ] = val
1075
+
1076
+ val = date (2010 , 10 , 10 )
1077
+ assert not block ._can_hold_element (val )
1078
+
1079
+ msg = (
1080
+ "'value' should be a 'Timestamp', 'NaT', "
1081
+ "or array of those. Got 'date' instead."
1082
+ )
1083
+ with pytest .raises (TypeError , match = msg ):
1084
+ arr [0 ] = val
1085
+
1154
1086
@pytest .mark .parametrize (
1155
1087
"value, dtype" ,
1156
1088
[
@@ -1280,3 +1212,37 @@ def test_dataframe_not_equal():
1280
1212
df1 = pd .DataFrame ({"a" : [1 , 2 ], "b" : ["s" , "d" ]})
1281
1213
df2 = pd .DataFrame ({"a" : ["s" , "d" ], "b" : [1 , 2 ]})
1282
1214
assert df1 .equals (df2 ) is False
1215
+
1216
+
1217
+ def test_missing_unicode_key ():
1218
+ df = DataFrame ({"a" : [1 ]})
1219
+ with pytest .raises (KeyError , match = "\u05d0 " ):
1220
+ df .loc [:, "\u05d0 " ] # should not raise UnicodeEncodeError
1221
+
1222
+
1223
+ def test_set_change_dtype_slice ():
1224
+ # GH#8850
1225
+ cols = MultiIndex .from_tuples ([("1st" , "a" ), ("2nd" , "b" ), ("3rd" , "c" )])
1226
+ df = DataFrame ([[1.0 , 2 , 3 ], [4.0 , 5 , 6 ]], columns = cols )
1227
+ df ["2nd" ] = df ["2nd" ] * 2.0
1228
+
1229
+ blocks = df ._to_dict_of_blocks ()
1230
+ assert sorted (blocks .keys ()) == ["float64" , "int64" ]
1231
+ tm .assert_frame_equal (
1232
+ blocks ["float64" ], DataFrame ([[1.0 , 4.0 ], [4.0 , 10.0 ]], columns = cols [:2 ])
1233
+ )
1234
+ tm .assert_frame_equal (blocks ["int64" ], DataFrame ([[3 ], [6 ]], columns = cols [2 :]))
1235
+
1236
+
1237
+ def test_interleave_non_unique_cols ():
1238
+ df = DataFrame (
1239
+ [[pd .Timestamp ("20130101" ), 3.5 ], [pd .Timestamp ("20130102" ), 4.5 ]],
1240
+ columns = ["x" , "x" ],
1241
+ index = [1 , 2 ],
1242
+ )
1243
+
1244
+ df_unique = df .copy ()
1245
+ df_unique .columns = ["x" , "y" ]
1246
+ assert df_unique .values .shape == df .values .shape
1247
+ tm .assert_numpy_array_equal (df_unique .values [0 ], df .values [0 ])
1248
+ tm .assert_numpy_array_equal (df_unique .values [1 ], df .values [1 ])
0 commit comments