File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments