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

63 lines
1.8 KiB
Python

try:
import numpy as np
except ImportError:
np = None
try:
import pandas as pd
except ImportError:
pd = None
from tests.numpy.testcase import NumpyBaseTestCase
from datastore_driver import errors
ErrorCodes = errors.ErrorCodes
class NullableTestCase(NumpyBaseTestCase):
def test_simple(self):
columns = 'a Nullable(Int32)'
data = [np.array([3, None, 2], dtype=object)]
with self.create_table(columns):
self.client.execute(
'INSERT INTO test (a) VALUES', data, columnar=True
)
query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(
inserted, '3\n\\N\n2\n'
)
inserted = self.client.execute(query, columnar=True)
self.assertArraysEqual(inserted[0], data[0])
self.assertEqual(inserted[0].dtype, object)
def test_simple_dataframe(self):
columns = (
'a Int64, '
'b Nullable(Float64), '
'c Nullable(String), '
'd Nullable(Int64)'
)
df = pd.DataFrame({
'a': [1, 2, 3],
'b': [1.0, None, np.nan],
'c': ['a', None, np.nan],
'd': [1, None, None],
}, dtype=object)
expected = pd.DataFrame({
'a': np.array([1, 2, 3], dtype=np.int64),
'b': np.array([1.0, None, np.nan], dtype=object),
'c': np.array(['a', None, None], dtype=object),
'd': np.array([1, None, None], dtype=object),
})
with self.create_table(columns):
rv = self.client.insert_dataframe('INSERT INTO test VALUES', df)
self.assertEqual(rv, 3)
df2 = self.client.query_dataframe('SELECT * FROM test ORDER BY a')
self.assertTrue(expected.equals(df2))