@@ -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,9 @@ 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 , policy = policy )
344
350
elif isinstance (data , ma .MaskedArray ):
345
351
import numpy .ma .mrecords as mrecords
346
352
# masked recarray
@@ -357,7 +363,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
357
363
else :
358
364
data = data .copy ()
359
365
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
360
- copy = copy )
366
+ copy = copy , policy = policy )
361
367
362
368
elif isinstance (data , (np .ndarray , Series , Index )):
363
369
if data .dtype .names :
@@ -368,10 +374,10 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
368
374
mgr = self ._init_dict (data , index , columns , dtype = dtype )
369
375
elif getattr (data , 'name' , None ) is not None :
370
376
mgr = self ._init_dict ({data .name : data }, index , columns ,
371
- dtype = dtype )
377
+ dtype = dtype , policy = policy )
372
378
else :
373
379
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
374
- copy = copy )
380
+ copy = copy , policy = policy )
375
381
elif isinstance (data , (list , types .GeneratorType )):
376
382
if isinstance (data , types .GeneratorType ):
377
383
data = list (data )
@@ -392,12 +398,12 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
392
398
index = _default_index (len (data ))
393
399
394
400
mgr = _arrays_to_mgr (arrays , columns , index , columns ,
395
- dtype = dtype )
401
+ dtype = dtype , policy = policy )
396
402
else :
397
403
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
398
- copy = copy )
404
+ copy = copy , policy = policy )
399
405
else :
400
- mgr = self ._init_dict ({}, index , columns , dtype = dtype )
406
+ mgr = self ._init_dict ({}, index , columns , dtype = dtype , policy = policy )
401
407
elif isinstance (data , collections .Iterator ):
402
408
raise TypeError ("data argument can't be an iterator" )
403
409
else :
@@ -412,13 +418,14 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
412
418
values = cast_scalar_to_array ((len (index ), len (columns )),
413
419
data , dtype = dtype )
414
420
mgr = self ._init_ndarray (values , index , columns ,
415
- dtype = values .dtype , copy = False )
421
+ dtype = values .dtype , copy = False ,
422
+ policy = policy )
416
423
else :
417
424
raise ValueError ('DataFrame constructor not properly called!' )
418
425
419
426
NDFrame .__init__ (self , mgr , fastpath = True )
420
427
421
- def _init_dict (self , data , index , columns , dtype = None ):
428
+ def _init_dict (self , data , index , columns , dtype = None , policy = None ):
422
429
"""
423
430
Segregate Series based on type and coerce into matrices.
424
431
Needs to handle a lot of exceptional cases.
@@ -470,9 +477,11 @@ def _init_dict(self, data, index, columns, dtype=None):
470
477
columns = data_names = Index (keys )
471
478
arrays = [data [k ] for k in keys ]
472
479
473
- return _arrays_to_mgr (arrays , data_names , index , columns , dtype = dtype )
480
+ return _arrays_to_mgr (arrays , data_names , index , columns , dtype = dtype ,
481
+ policy = policy )
474
482
475
- def _init_ndarray (self , values , index , columns , dtype = None , copy = False ):
483
+ def _init_ndarray (self , values , index , columns , dtype = None , copy = False ,
484
+ policy = None ):
476
485
# input must be a ndarray, list, Series, index
477
486
478
487
if isinstance (values , Series ):
@@ -542,7 +551,7 @@ def _get_axes(N, K, index=index, columns=columns):
542
551
if dtype is None and is_object_dtype (values ):
543
552
values = maybe_infer_to_datetimelike (values )
544
553
545
- return create_block_manager_from_blocks ([values ], [columns , index ])
554
+ return create_block_manager_from_blocks ([values ], [columns , index ], policy = policy )
546
555
547
556
@property
548
557
def axes (self ):
@@ -6018,7 +6027,7 @@ def isin(self, values):
6018
6027
ops .add_special_arithmetic_methods (DataFrame , ** ops .frame_special_funcs )
6019
6028
6020
6029
6021
- def _arrays_to_mgr (arrays , arr_names , index , columns , dtype = None ):
6030
+ def _arrays_to_mgr (arrays , arr_names , index , columns , dtype = None , policy = None ):
6022
6031
"""
6023
6032
Segregate Series based on type and coerce into matrices.
6024
6033
Needs to handle a lot of exceptional cases.
@@ -6035,7 +6044,7 @@ def _arrays_to_mgr(arrays, arr_names, index, columns, dtype=None):
6035
6044
# from BlockManager perspective
6036
6045
axes = [_ensure_index (columns ), _ensure_index (index )]
6037
6046
6038
- return create_block_manager_from_arrays (arrays , arr_names , axes )
6047
+ return create_block_manager_from_arrays (arrays , arr_names , axes , policy = policy )
6039
6048
6040
6049
6041
6050
def extract_index (data ):
0 commit comments