|
3 | 3 | from typing import Optional |
4 | 4 |
|
5 | 5 | import hypothesis.strategies as st |
6 | | -import npyodbc |
7 | 6 | import numpy as np |
8 | 7 | import pytest |
9 | 8 | from hypothesis import given, reject, settings |
10 | 9 | from numpy.testing import assert_allclose, assert_array_equal |
11 | 10 |
|
| 11 | +import npyodbc |
| 12 | + |
12 | 13 |
|
13 | 14 | @pytest.fixture(scope="module") |
14 | 15 | def connection() -> npyodbc.Connection: |
@@ -349,3 +350,27 @@ def test_fetchdictarray_coercion(cursor, int_dtype, float_dtype, values): |
349 | 350 | ) |
350 | 351 |
|
351 | 352 | cleanup(cursor) |
| 353 | + |
| 354 | + |
| 355 | +def test_null_floats(cursor): |
| 356 | + """Test that writing null values into a float column are NaN when retrieved.""" |
| 357 | + cursor.execute("CREATE TABLE t (f FLOAT NULL);") |
| 358 | + cursor.execute("INSERT INTO t VALUES (123.12345678), (NULL);") |
| 359 | + res = cursor.execute("SELECT * FROM t;").fetchdictarray(null_suffix="_isnull") |
| 360 | + |
| 361 | + assert_array_equal(res['f'], [123.12345678, np.nan]) |
| 362 | + assert_array_equal(res['f_isnull'], [False, True]) |
| 363 | + |
| 364 | + cleanup(cursor) |
| 365 | + |
| 366 | + |
| 367 | +def test_null_strings(cursor): |
| 368 | + """Test that null values in a text column are empty strings when retrieved.""" |
| 369 | + cursor.execute("CREATE TABLE t (f TEXT NULL);") |
| 370 | + cursor.execute("INSERT INTO t VALUES ('foo'), (NULL);") |
| 371 | + res = cursor.execute("SELECT * FROM t;").fetchdictarray(null_suffix="_isnull") |
| 372 | + |
| 373 | + assert_array_equal(res['f'], ['foo', '']) |
| 374 | + assert_array_equal(res['f_isnull'], [False, True]) |
| 375 | + |
| 376 | + cleanup(cursor) |
0 commit comments