Files
zeekay eb74c996a6 rename: this fork is ours — datastore_driver
Imports read `datastore_driver`, distribution `datastore-driver`, so nothing has to
import another product's name to talk to Hanzo Datastore.

Cut from upstream 0.2.9 — the version this stack already ran — rather than from
upstream HEAD, so it is a PURE RENAME with no behaviour change. Forking from
HEAD would have dragged versions along with the name (connect alone jumped
0.8.17 -> 1.6.0, a major), which is a different and much riskier change wearing
a rename's clothes.

X-ClickHouse-* headers are untouched: they are wire protocol the server sends
and expects, and a different token shape from the module name.
2026-07-26 11:01:28 -07:00

48 lines
1.4 KiB
Python

import numpy as np
import pandas as pd
from ..base import Column
class NumpyColumn(Column):
dtype = None
normalize_null_value = True
def read_items(self, n_items, buf):
data = buf.read(n_items * self.dtype.itemsize)
return np.frombuffer(data, self.dtype.newbyteorder('<'), n_items)
def write_items(self, items, buf):
buf.write(items.astype(self.dtype.newbyteorder('<')).tobytes())
def _write_nulls_map(self, items, buf):
s = self.make_null_struct(len(items))
nulls_map = self._get_nulls_map(items)
buf.write(s.pack(*nulls_map))
def _get_nulls_map(self, items):
return [bool(x) for x in pd.isnull(items)]
def _read_data(self, n_items, buf, nulls_map=None):
items = self.read_items(n_items, buf)
if self.after_read_items:
return self.after_read_items(items, nulls_map)
elif nulls_map is not None:
items = np.array(items, dtype=object)
np.place(items, nulls_map, None)
return items
def prepare_items(self, items):
nulls_map = pd.isnull(items)
# Always replace null values to null_value for proper inserts into
# non-nullable columns.
if isinstance(items, np.ndarray) and self.normalize_null_value:
items = np.array(items)
np.place(items, nulls_map, self.null_value)
return items