@@ -182,6 +182,12 @@ class DataFrame(NDFrame):
182
182
Data type to force, otherwise infer
183
183
copy : boolean, default False
184
184
Copy data from inputs. Only affects DataFrame / 2d ndarray input
185
+ policy : string, default None
186
+ Provide consolidation policy
187
+ - None : use default policy
188
+ - block : consolidate into blocks by dtype
189
+ - column : don't consolidate, but don't split blocks
190
+ - split : don't consolidate, force splitting of input
185
191
186
192
Examples
187
193
--------
@@ -211,7 +217,7 @@ def _constructor_expanddim(self):
211
217
return Panel
212
218
213
219
def __init__ (self , data = None , index = None , columns = None , dtype = None ,
214
- copy = False ):
220
+ copy = False , policy = None ):
215
221
if data is None :
216
222
data = {}
217
223
if dtype is not None :
@@ -222,9 +228,9 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
222
228
223
229
if isinstance (data , BlockManager ):
224
230
mgr = self ._init_mgr (data , axes = dict (index = index , columns = columns ),
225
- dtype = dtype , copy = copy )
231
+ dtype = dtype , copy = copy , policy = policy )
226
232
elif isinstance (data , dict ):
227
- mgr = self ._init_dict (data , index , columns , dtype = dtype )
233
+ mgr = self ._init_dict (data , index , columns , dtype = dtype , policy = policy )
228
234
elif isinstance (data , ma .MaskedArray ):
229
235
import numpy .ma .mrecords as mrecords
230
236
# masked recarray
@@ -241,7 +247,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
241
247
else :
242
248
data = data .copy ()
243
249
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
244
- copy = copy )
250
+ copy = copy , policy = policy )
245
251
246
252
elif isinstance (data , (np .ndarray , Series , Index )):
247
253
if data .dtype .names :
@@ -252,10 +258,10 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
252
258
mgr = self ._init_dict (data , index , columns , dtype = dtype )
253
259
elif getattr (data , 'name' , None ):
254
260
mgr = self ._init_dict ({data .name : data }, index , columns ,
255
- dtype = dtype )
261
+ dtype = dtype , policy = policy )
256
262
else :
257
263
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
258
- copy = copy )
264
+ copy = copy , policy = policy )
259
265
elif isinstance (data , (list , types .GeneratorType )):
260
266
if isinstance (data , types .GeneratorType ):
261
267
data = list (data )
@@ -274,12 +280,12 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
274
280
index = _default_index (len (data ))
275
281
276
282
mgr = _arrays_to_mgr (arrays , columns , index , columns ,
277
- dtype = dtype )
283
+ dtype = dtype , policy = policy )
278
284
else :
279
285
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
280
- copy = copy )
286
+ copy = copy , policy = policy )
281
287
else :
282
- mgr = self ._init_dict ({}, index , columns , dtype = dtype )
288
+ mgr = self ._init_dict ({}, index , columns , dtype = dtype , policy = policy )
283
289
elif isinstance (data , collections .Iterator ):
284
290
raise TypeError ("data argument can't be an iterator" )
285
291
else :
@@ -299,13 +305,13 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
299
305
values = np .empty ((len (index ), len (columns )), dtype = dtype )
300
306
values .fill (data )
301
307
mgr = self ._init_ndarray (values , index , columns , dtype = dtype ,
302
- copy = False )
308
+ copy = False , policy = policy )
303
309
else :
304
310
raise PandasError ('DataFrame constructor not properly called!' )
305
311
306
312
NDFrame .__init__ (self , mgr , fastpath = True )
307
313
308
- def _init_dict (self , data , index , columns , dtype = None ):
314
+ def _init_dict (self , data , index , columns , dtype = None , policy = None ):
309
315
"""
310
316
Segregate Series based on type and coerce into matrices.
311
317
Needs to handle a lot of exceptional cases.
@@ -359,10 +365,10 @@ def _init_dict(self, data, index, columns, dtype=None):
359
365
arrays = [data [k ] for k in keys ]
360
366
361
367
return _arrays_to_mgr (arrays , data_names , index , columns ,
362
- dtype = dtype )
368
+ dtype = dtype , policy = policy )
363
369
364
370
def _init_ndarray (self , values , index , columns , dtype = None ,
365
- copy = False ):
371
+ copy = False , policy = None ):
366
372
# input must be a ndarray, list, Series, index
367
373
368
374
if isinstance (values , Series ):
@@ -433,7 +439,7 @@ def _get_axes(N, K, index=index, columns=columns):
433
439
if dtype is None and is_object_dtype (values ):
434
440
values = _possibly_infer_to_datetimelike (values )
435
441
436
- return create_block_manager_from_blocks ([values ], [columns , index ])
442
+ return create_block_manager_from_blocks ([values ], [columns , index ], policy = policy )
437
443
438
444
@property
439
445
def axes (self ):
@@ -5082,7 +5088,7 @@ def combineMult(self, other):
5082
5088
5083
5089
_EMPTY_SERIES = Series ([])
5084
5090
5085
- def _arrays_to_mgr (arrays , arr_names , index , columns , dtype = None ):
5091
+ def _arrays_to_mgr (arrays , arr_names , index , columns , dtype = None , policy = None ):
5086
5092
"""
5087
5093
Segregate Series based on type and coerce into matrices.
5088
5094
Needs to handle a lot of exceptional cases.
@@ -5099,7 +5105,7 @@ def _arrays_to_mgr(arrays, arr_names, index, columns, dtype=None):
5099
5105
# from BlockManager perspective
5100
5106
axes = [_ensure_index (columns ), _ensure_index (index )]
5101
5107
5102
- return create_block_manager_from_arrays (arrays , arr_names , axes )
5108
+ return create_block_manager_from_arrays (arrays , arr_names , axes , policy = policy )
5103
5109
5104
5110
5105
5111
def extract_index (data ):
0 commit comments