Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_multiple_columns(dsn, configuration, column_backend):
with open_cursor(configuration) as cursor:
with query_fixture(cursor, configuration, 'INSERT TWO INTEGER COLUMNS') as table_name:
columns = [array([17, 23, 42], dtype='int64'), array([3, 2, 1], dtype='int64')]
if column_backend == 'arrow':
columns = [pa.Array.from_pandas(x) for x in columns]
columns = pa.Table.from_arrays(columns, ['column1', 'column2'])
cursor.executemanycolumns("INSERT INTO {} VALUES (?, ?)".format(table_name), columns)
results = cursor.execute("SELECT A, B FROM {} ORDER BY A".format(table_name)).fetchall()
assert results == [[17, 3], [23, 2], [42, 1]]
columns = [pa.array([True, False, None], type=pa.bool_()),
pa.array([1, 0, None]).cast(pa.int16()),
pa.array([1, 0, None]).cast(pa.int32()),
pa.array([1, 0, None]),
pa.array([1.0, 1.1, None]).cast(pa.float32()),
pa.array([1.0, 1.1, None]),
# no fixed-width string
pa.array(['a', 'b', None]),
pa.array(['a', 'b', None]),
(pa.array([1, 2, None]).cast(pa.int32())
.cast(pa.time32('s'))),
pa.array([datetime.datetime(2016, 1, 1, 12, 12, 12),
datetime.datetime(2017, 1, 1), None]),
pa.array([datetime.date(2016, 1, 1),
datetime.date(2017, 1, 1), None])]
table = pa.Table.from_arrays(columns, names=names)
con.load_table_arrow("all_types", table)
c.execute('drop table if exists all_types;')
def aggregate(self, data):
names = list(data[0].keys())
cols = {name: [] for name in names}
for entry in data:
for key in entry:
val = entry[key]
cols[key].append(val)
arrays = [pa.array(cols[col]) for col in cols]
table = pa.Table.from_arrays(arrays, names=names)
self.data = table
arrow_arrays = []
arrow_names = []
arrow_fields = []
for bq_field in bq_schema:
arrow_fields.append(bq_to_arrow_field(bq_field))
arrow_names.append(bq_field.name)
arrow_arrays.append(
bq_to_arrow_array(get_column_or_index(dataframe, bq_field.name), bq_field)
)
if all((field is not None for field in arrow_fields)):
return pyarrow.Table.from_arrays(
arrow_arrays, schema=pyarrow.schema(arrow_fields)
)
return pyarrow.Table.from_arrays(arrow_arrays, names=arrow_names)
def _node_table(
nodes,
node_id,
neo4j_label
):
attribute_names = _attributes_for_entities(nodes)
return arrow.Table.from_arrays(
[column for column in itertools.chain(
_intrinsic_node_columns(
nodes=nodes,
node_id=node_id,
neo4j_label=neo4j_label
),
_columns_for_entity(
entities=nodes,
entity_attributes=attribute_names
)
def to_arrow(self, progress_bar_type=None):
"""[Beta] Create an empty class:`pyarrow.Table`.
Args:
progress_bar_type (Optional[str]):
Ignored. Added for compatibility with RowIterator.
Returns:
pyarrow.Table:
An empty :class:`pyarrow.Table`.
"""
if pyarrow is None:
raise ValueError(_NO_PYARROW_ERROR)
return pyarrow.Table.from_arrays(())
bqstorage_client=None,
create_bqstorage_client=False,
):
"""[Beta] Create an empty class:`pyarrow.Table`.
Args:
progress_bar_type (Optional[str]): Ignored. Added for compatibility with RowIterator.
bqstorage_client (Any): Ignored. Added for compatibility with RowIterator.
create_bqstorage_client (bool): Ignored. Added for compatibility with RowIterator.
Returns:
pyarrow.Table: An empty :class:`pyarrow.Table`.
"""
if pyarrow is None:
raise ValueError(_NO_PYARROW_ERROR)
return pyarrow.Table.from_arrays(())
def arrow_table_from_vaex_df(ds, column_names=None, selection=None, strings=True, virtual=False):
"""Implementation of Dataset.to_arrow_table"""
names = []
arrays = []
for name, array in ds.to_items(column_names=column_names, selection=selection, strings=strings, virtual=virtual):
names.append(name)
arrays.append(arrow_array_from_numpy_array(array))
return pyarrow.Table.from_arrays(arrays, names)
raise ValueError(
u"bq_schema is missing fields from dataframe: {}".format(missing_fields)
)
arrow_arrays = []
arrow_names = []
arrow_fields = []
for bq_field in bq_schema:
arrow_fields.append(bq_to_arrow_field(bq_field))
arrow_names.append(bq_field.name)
arrow_arrays.append(
bq_to_arrow_array(get_column_or_index(dataframe, bq_field.name), bq_field)
)
if all((field is not None for field in arrow_fields)):
return pyarrow.Table.from_arrays(
arrow_arrays, schema=pyarrow.schema(arrow_fields)
)
return pyarrow.Table.from_arrays(arrow_arrays, names=arrow_names)