@@ -266,6 +266,12 @@ class DataFrame(NDFrame):
266
266
Data type to force. Only a single dtype is allowed. If None, infer
267
267
copy : boolean, default False
268
268
Copy data from inputs. Only affects DataFrame / 2d ndarray input
269
+ policy : string, default None
270
+ Provide consolidation policy
271
+ - None : use default policy
272
+ - block : consolidate into blocks by dtype
273
+ - column : don't consolidate, but don't split blocks
274
+ - split : don't consolidate, force splitting of input
269
275
270
276
Examples
271
277
--------
@@ -327,7 +333,7 @@ def _constructor_expanddim(self):
327
333
return Panel
328
334
329
335
def __init__ (self , data = None , index = None , columns = None , dtype = None ,
330
- copy = False ):
336
+ copy = False , policy = None ):
331
337
if data is None :
332
338
data = {}
333
339
if dtype is not None :
@@ -338,9 +344,10 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
338
344
339
345
if isinstance (data , BlockManager ):
340
346
mgr = self ._init_mgr (data , axes = dict (index = index , columns = columns ),
341
- dtype = dtype , copy = copy )
347
+ dtype = dtype , copy = copy , policy = policy )
342
348
elif isinstance (data , dict ):
343
- mgr = self ._init_dict (data , index , columns , dtype = dtype )
349
+ mgr = self ._init_dict (data , index , columns , dtype = dtype ,
350
+ policy = policy )
344
351
elif isinstance (data , ma .MaskedArray ):
345
352
import numpy .ma .mrecords as mrecords
346
353
# masked recarray
@@ -357,7 +364,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
357
364
else :
358
365
data = data .copy ()
359
366
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
360
- copy = copy )
367
+ copy = copy , policy = policy )
361
368
362
369
elif isinstance (data , (np .ndarray , Series , Index )):
363
370
if data .dtype .names :
@@ -368,10 +375,10 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
368
375
mgr = self ._init_dict (data , index , columns , dtype = dtype )
369
376
elif getattr (data , 'name' , None ) is not None :
370
377
mgr = self ._init_dict ({data .name : data }, index , columns ,
371
- dtype = dtype )
378
+ dtype = dtype , policy = policy )
372
379
else :
373
380
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
374
- copy = copy )
381
+ copy = copy , policy = policy )
375
382
elif isinstance (data , (list , types .GeneratorType )):
376
383
if isinstance (data , types .GeneratorType ):
377
384
data = list (data )
@@ -392,12 +399,13 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
392
399
index = _default_index (len (data ))
393
400
394
401
mgr = _arrays_to_mgr (arrays , columns , index , columns ,
395
- dtype = dtype )
402
+ dtype = dtype , policy = policy )
396
403
else :
397
404
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
398
- copy = copy )
405
+ copy = copy , policy = policy )
399
406
else :
400
- mgr = self ._init_dict ({}, index , columns , dtype = dtype )
407
+ mgr = self ._init_dict ({}, index , columns , dtype = dtype ,
408
+ policy = policy )
401
409
elif isinstance (data , collections .Iterator ):
402
410
raise TypeError ("data argument can't be an iterator" )
403
411
else :
@@ -412,13 +420,14 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
412
420
values = cast_scalar_to_array ((len (index ), len (columns )),
413
421
data , dtype = dtype )
414
422
mgr = self ._init_ndarray (values , index , columns ,
415
- dtype = values .dtype , copy = False )
423
+ dtype = values .dtype , copy = False ,
424
+ policy = policy )
416
425
else :
417
426
raise ValueError ('DataFrame constructor not properly called!' )
418
427
419
428
NDFrame .__init__ (self , mgr , fastpath = True )
420
429
421
- def _init_dict (self , data , index , columns , dtype = None ):
430
+ def _init_dict (self , data , index , columns , dtype = None , policy = None ):
422
431
"""
423
432
Segregate Series based on type and coerce into matrices.
424
433
Needs to handle a lot of exceptional cases.
@@ -470,9 +479,11 @@ def _init_dict(self, data, index, columns, dtype=None):
470
479
columns = data_names = Index (keys )
471
480
arrays = [data [k ] for k in keys ]
472
481
473
- return _arrays_to_mgr (arrays , data_names , index , columns , dtype = dtype )
482
+ return _arrays_to_mgr (arrays , data_names , index , columns , dtype = dtype ,
483
+ policy = policy )
474
484
475
- def _init_ndarray (self , values , index , columns , dtype = None , copy = False ):
485
+ def _init_ndarray (self , values , index , columns , dtype = None , copy = False ,
486
+ policy = None ):
476
487
# input must be a ndarray, list, Series, index
477
488
478
489
if isinstance (values , Series ):
@@ -542,7 +553,8 @@ def _get_axes(N, K, index=index, columns=columns):
542
553
if dtype is None and is_object_dtype (values ):
543
554
values = maybe_infer_to_datetimelike (values )
544
555
545
- return create_block_manager_from_blocks ([values ], [columns , index ])
556
+ return create_block_manager_from_blocks ([values ], [columns , index ],
557
+ policy = policy )
546
558
547
559
@property
548
560
def axes (self ):
@@ -6018,7 +6030,7 @@ def isin(self, values):
6018
6030
ops .add_special_arithmetic_methods (DataFrame , ** ops .frame_special_funcs )
6019
6031
6020
6032
6021
- def _arrays_to_mgr (arrays , arr_names , index , columns , dtype = None ):
6033
+ def _arrays_to_mgr (arrays , arr_names , index , columns , dtype = None , policy = None ):
6022
6034
"""
6023
6035
Segregate Series based on type and coerce into matrices.
6024
6036
Needs to handle a lot of exceptional cases.
@@ -6035,7 +6047,8 @@ def _arrays_to_mgr(arrays, arr_names, index, columns, dtype=None):
6035
6047
# from BlockManager perspective
6036
6048
axes = [_ensure_index (columns ), _ensure_index (index )]
6037
6049
6038
- return create_block_manager_from_arrays (arrays , arr_names , axes )
6050
+ return create_block_manager_from_arrays (arrays , arr_names , axes ,
6051
+ policy = policy )
6039
6052
6040
6053
6041
6054
def extract_index (data ):
0 commit comments