MCPcopy Create free account
hub / github.com/apache/arrow / dataframe_with_lists

Function dataframe_with_lists

python/pyarrow/tests/pandas_examples.py:83–172  ·  view source on GitHub ↗

Dataframe with list columns of every possible primitive type. Returns ------- df: pandas.DataFrame schema: pyarrow.Schema Arrow schema definition that is in line with the constructed df. parquet_compatible: bool Exclude types not supported by parquet

(include_index=False, parquet_compatible=False)

Source from the content-addressed store, hash-verified

81
82
83def dataframe_with_lists(include_index=False, parquet_compatible=False):
84 """
85 Dataframe with list columns of every possible primitive type.
86
87 Returns
88 -------
89 df: pandas.DataFrame
90 schema: pyarrow.Schema
91 Arrow schema definition that is in line with the constructed df.
92 parquet_compatible: bool
93 Exclude types not supported by parquet
94 """
95 arrays = OrderedDict()
96 fields = []
97
98 fields.append(pa.field('int64', pa.list_(pa.int64())))
99 arrays['int64'] = [
100 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
101 [0, 1, 2, 3, 4],
102 None,
103 [],
104 np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9] * 2,
105 dtype=np.int64)[::2]
106 ]
107 fields.append(pa.field('double', pa.list_(pa.float64())))
108 arrays['double'] = [
109 [0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],
110 [0., 1., 2., 3., 4.],
111 None,
112 [],
113 np.array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.] * 2)[::2],
114 ]
115 fields.append(pa.field('bytes_list', pa.list_(pa.binary())))
116 arrays['bytes_list'] = [
117 [b"1", b"f"],
118 None,
119 [b"1"],
120 [b"1", b"2", b"3"],
121 [],
122 ]
123 fields.append(pa.field('str_list', pa.list_(pa.string())))
124 arrays['str_list'] = [
125 ["1", "ä"],
126 None,
127 ["1"],
128 ["1", "2", "3"],
129 [],
130 ]
131
132 date_data = [
133 [],
134 [date(2018, 1, 1), date(2032, 12, 30)],
135 [date(2000, 6, 7)],
136 None,
137 [date(1969, 6, 9), date(1972, 7, 3)]
138 ]
139 time_data = [
140 [time(23, 11, 11), time(1, 2, 3), time(23, 59, 59)],

Callers 4

test_chunked_table_writeFunction · 0.90
test_column_of_listsFunction · 0.90
test_column_of_listsMethod · 0.85

Calls 5

appendMethod · 0.45
fieldMethod · 0.45
arrayMethod · 0.45
stringMethod · 0.45
schemaMethod · 0.45

Tested by 4

test_chunked_table_writeFunction · 0.72
test_column_of_listsFunction · 0.72
test_column_of_listsMethod · 0.68