2
2
Functions for preparing various inputs passed to the DataFrame or Series
3
3
constructors before passing them to a BlockManager.
4
4
"""
5
- from collections import OrderedDict , abc
5
+ from collections import abc
6
6
7
7
import numpy as np
8
8
import numpy .ma as ma
9
9
10
10
from pandas ._libs import lib
11
- import pandas .compat as compat
12
- from pandas .compat import PY36
13
11
14
12
from pandas .core .dtypes .cast import (
15
13
construct_1d_arraylike_from_scalar ,
@@ -235,7 +233,7 @@ def init_dict(data, index, columns, dtype=None):
235
233
arrays .loc [missing ] = [val ] * missing .sum ()
236
234
237
235
else :
238
- keys = com . dict_keys_to_ordered_list (data )
236
+ keys = list (data . keys () )
239
237
columns = data_names = Index (keys )
240
238
arrays = (com .maybe_iterable_to_list (data [k ]) for k in keys )
241
239
# GH#24096 need copy to be deep for datetime64tz case
@@ -331,16 +329,13 @@ def extract_index(data):
331
329
have_raw_arrays = False
332
330
have_series = False
333
331
have_dicts = False
334
- have_ordered = False
335
332
336
333
for val in data :
337
334
if isinstance (val , ABCSeries ):
338
335
have_series = True
339
336
indexes .append (val .index )
340
337
elif isinstance (val , dict ):
341
338
have_dicts = True
342
- if isinstance (val , OrderedDict ):
343
- have_ordered = True
344
339
indexes .append (list (val .keys ()))
345
340
elif is_list_like (val ) and getattr (val , "ndim" , 1 ) == 1 :
346
341
have_raw_arrays = True
@@ -352,7 +347,7 @@ def extract_index(data):
352
347
if have_series :
353
348
index = _union_indexes (indexes )
354
349
elif have_dicts :
355
- index = _union_indexes (indexes , sort = not ( compat . PY36 or have_ordered ) )
350
+ index = _union_indexes (indexes , sort = False )
356
351
357
352
if have_raw_arrays :
358
353
lengths = list (set (raw_lengths ))
@@ -531,7 +526,7 @@ def _list_of_dict_to_arrays(data, columns, coerce_float=False, dtype=None):
531
526
"""Convert list of dicts to numpy arrays
532
527
533
528
if `columns` is not passed, column names are inferred from the records
534
- - for OrderedDict and (on Python>=3.6) dicts, the column names match
529
+ - for OrderedDict and dicts, the column names match
535
530
the key insertion-order from the first record to the last.
536
531
- For other kinds of dict-likes, the keys are lexically sorted.
537
532
@@ -551,8 +546,7 @@ def _list_of_dict_to_arrays(data, columns, coerce_float=False, dtype=None):
551
546
552
547
if columns is None :
553
548
gen = (list (x .keys ()) for x in data )
554
- types = (dict , OrderedDict ) if PY36 else OrderedDict
555
- sort = not any (isinstance (d , types ) for d in data )
549
+ sort = not any (isinstance (d , dict ) for d in data )
556
550
columns = lib .fast_unique_multiple_list_gen (gen , sort = sort )
557
551
558
552
# assure that they are of the base dict class and not of derived
0 commit comments