@@ -355,6 +355,12 @@ class DataFrame(NDFrame):
355
355
Data type to force. Only a single dtype is allowed. If None, infer.
356
356
copy : bool, default False
357
357
Copy data from inputs. Only affects DataFrame / 2d ndarray input.
358
+ policy : string, default None
359
+ Provide consolidation policy
360
+ - None : use default policy
361
+ - block : consolidate into blocks by dtype
362
+ - column : don't consolidate, but don't split blocks
363
+ - split : don't consolidate, force splitting of input
358
364
359
365
See Also
360
366
--------
@@ -363,6 +369,9 @@ class DataFrame(NDFrame):
363
369
read_csv : Read a comma-separated values (csv) file into DataFrame.
364
370
read_table : Read general delimited file into DataFrame.
365
371
read_clipboard : Read text from clipboard into DataFrame.
372
+ Data type to force. Only a single dtype is allowed. If None, infer
373
+ copy : boolean, default False
374
+ Copy data from inputs. Only affects DataFrame / 2d ndarray input
366
375
367
376
Examples
368
377
--------
@@ -426,6 +435,7 @@ def __init__(
426
435
columns : Optional [Axes ] = None ,
427
436
dtype : Optional [Dtype ] = None ,
428
437
copy : bool = False ,
438
+ policy = None ,
429
439
):
430
440
if data is None :
431
441
data = {}
@@ -437,10 +447,11 @@ def __init__(
437
447
438
448
if isinstance (data , BlockManager ):
439
449
mgr = self ._init_mgr (
440
- data , axes = dict (index = index , columns = columns ), dtype = dtype , copy = copy
450
+ data , axes = dict (index = index , columns = columns ), dtype = dtype , copy = copy ,
451
+ policy = policy ,
441
452
)
442
453
elif isinstance (data , dict ):
443
- mgr = init_dict (data , index , columns , dtype = dtype )
454
+ mgr = init_dict (data , index , columns , dtype = dtype , policy = policy )
444
455
elif isinstance (data , ma .MaskedArray ):
445
456
import numpy .ma .mrecords as mrecords
446
457
@@ -457,19 +468,19 @@ def __init__(
457
468
data [mask ] = fill_value
458
469
else :
459
470
data = data .copy ()
460
- mgr = init_ndarray (data , index , columns , dtype = dtype , copy = copy )
471
+ mgr = init_ndarray (data , index , columns , dtype = dtype , copy = copy , policy = policy )
461
472
462
473
elif isinstance (data , (np .ndarray , Series , Index )):
463
474
if data .dtype .names :
464
475
data_columns = list (data .dtype .names )
465
476
data = {k : data [k ] for k in data_columns }
466
477
if columns is None :
467
478
columns = data_columns
468
- mgr = init_dict (data , index , columns , dtype = dtype )
479
+ mgr = init_dict (data , index , columns , dtype = dtype , policy = policy )
469
480
elif getattr (data , "name" , None ) is not None :
470
- mgr = init_dict ({data .name : data }, index , columns , dtype = dtype )
481
+ mgr = init_dict ({data .name : data }, index , columns , dtype = dtype , policy = policy )
471
482
else :
472
- mgr = init_ndarray (data , index , columns , dtype = dtype , copy = copy )
483
+ mgr = init_ndarray (data , index , columns , dtype = dtype , copy = copy , policy = policy )
473
484
474
485
# For data is list-like, or Iterable (will consume into list)
475
486
elif isinstance (data , abc .Iterable ) and not isinstance (data , (str , bytes )):
@@ -493,11 +504,11 @@ def __init__(
493
504
else :
494
505
index = ibase .default_index (len (data ))
495
506
496
- mgr = arrays_to_mgr (arrays , columns , index , columns , dtype = dtype )
507
+ mgr = arrays_to_mgr (arrays , columns , index , columns , dtype = dtype , policy = policy )
497
508
else :
498
- mgr = init_ndarray (data , index , columns , dtype = dtype , copy = copy )
509
+ mgr = init_ndarray (data , index , columns , dtype = dtype , copy = copy , policy = policy )
499
510
else :
500
- mgr = init_dict ({}, index , columns , dtype = dtype )
511
+ mgr = init_dict ({}, index , columns , dtype = dtype , policy = policy )
501
512
else :
502
513
try :
503
514
arr = np .array (data , dtype = dtype , copy = copy )
@@ -513,7 +524,7 @@ def __init__(
513
524
(len (index ), len (columns )), data , dtype = dtype
514
525
)
515
526
mgr = init_ndarray (
516
- values , index , columns , dtype = values .dtype , copy = False
527
+ values , index , columns , dtype = values .dtype , copy = False , policy = policy ,
517
528
)
518
529
else :
519
530
raise ValueError ("DataFrame constructor not properly called!" )
@@ -575,7 +586,7 @@ def _is_homogeneous_type(self) -> bool:
575
586
Index._is_homogeneous_type : Whether the object has a single
576
587
dtype.
577
588
MultiIndex._is_homogeneous_type : Whether all the levels of a
578
- MultiIndex have the same dtype.
589
+ have the same dtype.
579
590
580
591
Examples
581
592
--------
0 commit comments