Skip to content

Commit 07ac891

Browse files
committed
test: Use numpy but not columnar format to improve test coverage
1 parent 343bbde commit 07ac891

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/backends/tests.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,77 @@ def test_use_numpy_query(self):
691691
),
692692
)
693693

694+
@unittest.skipUnless(check_numpy(), "numpy is not installed")
695+
def test_use_numpy_but_not_columnar_format(self):
696+
sql = """
697+
SELECT toDateTime32('2022-01-01 01:00:05', 'UTC'), number, number*2.5
698+
FROM system.numbers
699+
LIMIT 3
700+
"""
701+
import numpy as np
702+
703+
with connections["s2r1"].cursor() as cursorWrapper:
704+
with cursorWrapper.cursor.set_query_args(
705+
columnar=False, use_numpy=True
706+
) as cursor:
707+
cursor.execute(sql)
708+
np.testing.assert_equal(
709+
cursor.fetchall(),
710+
[
711+
np.array(
712+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 0, 0.0],
713+
dtype=object,
714+
),
715+
np.array(
716+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 1, 2.5],
717+
dtype=object,
718+
),
719+
np.array(
720+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 2, 5.0],
721+
dtype=object,
722+
),
723+
],
724+
)
725+
726+
cursor.execute(sql)
727+
np.testing.assert_equal(
728+
cursor.fetchmany(2),
729+
[
730+
np.array(
731+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 0, 0.0],
732+
dtype="object",
733+
),
734+
np.array(
735+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 1, 2.5],
736+
dtype="object",
737+
),
738+
],
739+
)
740+
741+
actual_results = [
742+
r
743+
for results in iter(lambda: cursor.fetchmany(2), [])
744+
for r in results
745+
]
746+
np.testing.assert_equal(
747+
actual_results,
748+
[
749+
np.array(
750+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 2, 5.0],
751+
dtype="object",
752+
),
753+
],
754+
)
755+
756+
cursor.execute(sql)
757+
np.testing.assert_equal(
758+
cursor.fetchone(),
759+
np.array(
760+
[datetime.datetime(2022, 1, 1, 1, 0, 5), 0, 0.0],
761+
dtype="object",
762+
),
763+
)
764+
694765

695766
# These tests aren't conditional because it would require differentiating
696767
# between MySQL+InnoDB and MySQL+MYISAM (something we currently can't do).

0 commit comments

Comments
 (0)