@@ -23,7 +23,7 @@ def get_float_mat(n, k):
23
23
N = 10
24
24
25
25
def get_float_ex (cols = ['a' , 'c' , 'e' ]):
26
- floats = get_float_mat (N , 3 ).T
26
+ floats = get_float_mat (N , len ( cols ) ).T
27
27
return make_block (floats , cols , TEST_COLS )
28
28
29
29
def get_complex_ex (cols = ['h' ]):
@@ -192,7 +192,15 @@ def setUp(self):
192
192
get_bool_ex (),
193
193
get_int_ex (),
194
194
get_complex_ex ()]
195
- self .mgr = BlockManager .from_blocks (self .blocks , np .arange (N ))
195
+
196
+ all_items = [b .items for b in self .blocks ]
197
+
198
+ items = sorted (all_items [0 ].append (all_items [1 :]))
199
+ items = Index (items )
200
+ for b in self .blocks :
201
+ b .ref_items = items
202
+
203
+ self .mgr = BlockManager (self .blocks , [items , np .arange (N )])
196
204
197
205
def test_constructor_corner (self ):
198
206
pass
@@ -204,8 +212,12 @@ def test_attrs(self):
204
212
def test_is_mixed_dtype (self ):
205
213
self .assert_ (self .mgr .is_mixed_dtype ())
206
214
215
+ items = Index (['a' , 'b' ])
207
216
blocks = [get_bool_ex (['a' ]), get_bool_ex (['b' ])]
208
- mgr = BlockManager .from_blocks (blocks , np .arange (N ))
217
+ for b in blocks :
218
+ b .ref_items = items
219
+
220
+ mgr = BlockManager (blocks , [items , np .arange (N )])
209
221
self .assert_ (not mgr .is_mixed_dtype ())
210
222
211
223
def test_is_indexed_like (self ):
@@ -233,6 +245,15 @@ def test_union_block_items(self):
233
245
self .assert_ (np .array_equal (internals ._union_block_items (blocks ),
234
246
['a' , 'b' , 'c' , 'd' , 'e' , 'f' ]))
235
247
248
+ def test_duplicate_item_failure (self ):
249
+ items = Index (['a' , 'a' ])
250
+ blocks = [get_bool_ex (['a' ]), get_float_ex (['a' ])]
251
+ for b in blocks :
252
+ b .ref_items = items
253
+
254
+ mgr = BlockManager (blocks , [items , np .arange (N )])
255
+ self .assertRaises (Exception , mgr .iget , 1 )
256
+
236
257
def test_contains (self ):
237
258
self .assert_ ('a' in self .mgr )
238
259
self .assert_ ('baz' not in self .mgr )
@@ -288,27 +309,35 @@ def test_as_matrix(self):
288
309
pass
289
310
290
311
def test_as_matrix_int_bool (self ):
312
+ items = Index (['a' , 'b' ])
313
+
291
314
blocks = [get_bool_ex (['a' ]), get_bool_ex (['b' ])]
315
+ for b in blocks :
316
+ b .ref_items = items
292
317
index_sz = blocks [0 ].values .shape [1 ]
293
- mgr = BlockManager . from_blocks (blocks , np .arange (index_sz ))
318
+ mgr = BlockManager (blocks , [ items , np .arange (index_sz )] )
294
319
self .assert_ (mgr .as_matrix ().dtype == np .bool_ )
295
320
296
321
blocks = [get_int_ex (['a' ]), get_int_ex (['b' ])]
297
- mgr = BlockManager .from_blocks (blocks , np .arange (index_sz ))
322
+ for b in blocks :
323
+ b .ref_items = items
324
+
325
+ mgr = BlockManager (blocks , [items , np .arange (index_sz )])
298
326
self .assert_ (mgr .as_matrix ().dtype == np .int64 )
299
327
300
328
def test_as_matrix_datetime (self ):
329
+ items = Index (['h' , 'g' ])
301
330
blocks = [get_dt_ex (['h' ]), get_dt_ex (['g' ])]
331
+ for b in blocks :
332
+ b .ref_items = items
333
+
302
334
index_sz = blocks [0 ].values .shape [1 ]
303
- mgr = BlockManager . from_blocks (blocks , np .arange (index_sz ))
335
+ mgr = BlockManager (blocks , [ items , np .arange (index_sz )] )
304
336
self .assert_ (mgr .as_matrix ().dtype == 'M8[ns]' )
305
337
306
338
def test_xs (self ):
307
339
pass
308
340
309
- def test_from_blocks (self ):
310
- self .assert_ (np .array_equal (self .mgr .items , TEST_COLS ))
311
-
312
341
def test_interleave (self ):
313
342
pass
314
343
0 commit comments