Skip to content

Commit 2c4fde7

Browse files
committed
fix tests
1 parent b249687 commit 2c4fde7

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

quasardb/pandas/__init__.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,28 @@ def _extract_columns(
409409
# Grab all columns from the DataFrame in the order of table columns,
410410
# put None if not present in df.
411411
for i in range(len(cinfos)):
412-
(cname, _) = cinfos[i]
412+
(cname, ctype) = cinfos[i]
413413

414414
if cname in df.columns:
415-
arr = df[cname].array
416-
ret[cname] = ma.masked_array(arr.to_numpy(copy=False), mask=arr.isna())
415+
#arr = df[cname].array
416+
#ret[cname] = ma.masked_array(arr.to_numpy(copy=False), mask=arr.isna())
417+
series = df[cname]
418+
419+
# Ensure the numpy array dtype matches what the backend expects. Pandas will
420+
# often upcast integer columns with nulls to object dtype, which will fail the
421+
# dtype validation in qdbnp.write_arrays when using Arrow push. We explicitly
422+
# coerce to the preferred dtype for the column type and rely on the mask to
423+
# represent nulls. Using the Series keeps the mask handling consistent for
424+
# masked arrays as well.
425+
expected_dtype = qdbnp._best_dtype_for_ctype(ctype)
426+
mask = series.isna().to_numpy(dtype=bool, copy=False)
427+
data = series.to_numpy(
428+
copy=False,
429+
dtype=expected_dtype,
430+
na_value=np.zeros(1, dtype=expected_dtype)[0],
431+
)
432+
433+
ret[cname] = ma.masked_array(data, mask=mask)
417434

418435
return ret
419436

0 commit comments

Comments
 (0)