Skip to content

Commit

Permalink
Merge pull request #441 from Simon-Chenzw/master
Browse files Browse the repository at this point in the history
Support pandas StringArray and ArrowStringArray
  • Loading branch information
xzkostyan authored Jul 5, 2024
2 parents 59ea586 + 40e9a6f commit 48403ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clickhouse_driver/numpy/helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import numpy as np
import pandas as pd
from pandas.core.arrays import ExtensionArray


def column_chunks(columns, n):
for column in columns:
if not isinstance(column, (np.ndarray, pd.DatetimeIndex)):
if not isinstance(
column, (np.ndarray, pd.DatetimeIndex, ExtensionArray)
):
raise TypeError(
'Unsupported column type: {}. '
'ndarray/DatetimeIndex is expected.'
'ndarray/DatetimeIndex/ExtensionArray is expected.'
.format(type(column))
)

Expand Down
16 changes: 16 additions & 0 deletions tests/numpy/columns/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
except ImportError:
np = None

try:
import pandas as pd
except ImportError:
pd = None

from tests.numpy.testcase import NumpyBaseTestCase


Expand Down Expand Up @@ -40,6 +45,17 @@ def test_nullable(self):
)
self.assertEqual(inserted[0].dtype, object)

def test_insert_pandas_string(self):
with self.create_table('a String'):
df = pd.DataFrame({'a': ['a', 'b', 'c']}, dtype='string')
self.client.insert_dataframe(
'INSERT INTO test VALUES', dataframe=df
)

query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(inserted, 'a\nb\nc\n')


class ByteStringTestCase(NumpyBaseTestCase):
client_kwargs = {'settings': {'strings_as_bytes': True, 'use_numpy': True}}
Expand Down

0 comments on commit 48403ed

Please sign in to comment.