GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: keep NaN distinct from NULL in float columns when pandas is enabled by maharanay22 · Pull Request #979 · databricks/databricks-sql-python

Conversation

@maharanay22

@maharanay22 maharanay22 commented Oct 8, 2026

Copy link
Copy Markdown

What type of PR is this?

  • Bug Fix

Description

Fixes #978.

With pandas enabled (the default), ResultSet._convert_arrow_table maps float32/float64 columns to pandas' nullable Float32Dtype/Float64Dtype. That conversion turns IEEE NaN into pd.NA, and to_numpy(na_value=None) then returns None, so a NaN in a FLOAT or DOUBLE column could not be told apart from SQL NULL. With _disable_pandas=True the same data already came back as float('nan'). For example, [NaN, NULL, inf, 1.5] read back as [None, None, inf, 1.5] by default and [nan, None, inf, 1.5] with _disable_pandas=True, on both pandas 2.3.3 and 3.0.6.

After the object array is built, NaN is set back on the cells that are NaN in the Arrow column, using a vectorized pyarrow.compute.is_nan mask. NULL stays None and other values are unchanged. Tables without float columns do no extra work, and for float columns the cost is one boolean mask per column (about 5 ms per million rows locally, next to roughly 80 ms for the existing pandas conversion).

This is a user-visible change: code that treated a NaN result as None will now see float('nan'). Changelog entry added under # Unreleased.

How is this tested?

  • Unit tests

New tests in tests/unit/test_pandas_compatibility.py check exact row values for float32 and float64 columns containing NaN, NULL, inf, -inf and a normal value (split over two chunks, after a non-float column), and check that the default and _disable_pandas=True paths return the same rows. Both fail on main and pass with this change, under pandas 2.3.3 and 3.0.6. Full unit suite: 1022 passed, 5 skipped.

Related Tickets & Documents

Fixes #978. Related: #960 edits the same function for nested types. This change sits right after to_numpy and only uses the table that went through pandas, so either PR rebases onto the other with a one-name change (table_renamed to scalar_table). Both PRs also add a # Unreleased changelog section, so the second one to merge will need a trivial changelog rebase.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@maharanay22 maharanay22 mentioned this pull request Oct 10, 2026
fix: avoid ZeroDivisionError when a CloudFetch download takes no measurable time #977
Open
3 tasks done
@maharanay22
maharanay22 force-pushed the fix-nan-float-null-conversion branch 2 times, most recently from d836dcb to 2057880 Compare October 22, 2026 18:06
@maharanay22
fix: keep NaN distinct from NULL in float columns when pandas is enabled
2546c2f
With pandas enabled (the default), _convert_arrow_table maps float32 and
float64 columns to pandas' nullable Float32Dtype/Float64Dtype. Converting
an Arrow float column to those dtypes turns IEEE NaN into pd.NA, and
to_numpy(na_value=None) then returns None for it, so a NaN value could
not be told apart from SQL NULL. With _disable_pandas=True the same data
already came back as float('nan').

After building the object array, set NaN back on the cells that are NaN
in the Arrow column, using a vectorized pyarrow.compute.is_nan mask.
NULL stays None, other values are unchanged, and tables without float
columns take no extra work.

Signed-off-by: Maha Rana Yadavalli <[email protected]>
@maharanay22
maharanay22 force-pushed the fix-nan-float-null-conversion branch from 2057880 to 2546c2f Compare October 29, 2026 04:04
@maharanay22 maharanay22 mentioned this pull request Oct 30, 2026
NaN in FLOAT/DOUBLE columns is returned as None (same as NULL) when pandas is enabled #978
Open
vuanhphung
vuanhphung reviewed Oct 30, 2026
View reviewed changes
Comment thread src/databricks/sql/result_set.py Outdated
# The nullable float dtypes turn IEEE NaN into NA, which would make it
# indistinguishable from SQL NULL, so restore NaN values from Arrow.
for i, field in enumerate(table_renamed.schema):
if pyarrow.types.is_floating(field.type):

@vuanhphung vuanhphung Oct 30, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I think we should add some cheap optimization such as

nan_mask = pyarrow.compute.is_nan(table_renamed.column(i))

if not pyarrow.compute.any(nan_mask).as_py():
      continue

if nan_mask.null_count:
      nan_mask = nan_mask.fill_null(False)

res[nan_mask.to_numpy(), i] = float("nan")

to reduce the overhead of this conversion

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@maharanay22
perf: skip NaN restore for float columns without NaN
029d9bb
Signed-off-by: Maha Rana Yadavalli <[email protected]>
@maharanay22

maharanay22 commented Nov 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

@vuanhphung thanks, good idea. I added the early exit when a column has no NaN and fill nulls in the mask before indexing

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maharanay22
Merge main into fix-nan-float-null-conversion
849e567
Signed-off-by: Maha Rana Yadavalli <[email protected]>
@maharanay22

maharanay22 commented Nov 7, 2026

Copy link
Copy Markdown
Author

@vuanhphung merged main into this, #977 and #982 to resolve the CHANGELOG conflict with 4.9.0. Could you approve the CI runs when you have time?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maharanay22
Merge main into fix-nan-float-null-conversion
ca2d4d8
Signed-off-by: Maha Rana Yadavalli <[email protected]>
@maharanay22

maharanay22 commented Nov 12, 2026

Copy link
Copy Markdown
Author

@vuanhphung I addressed your review. Could you take another look when you have time?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vuanhphung vuanhphung mentioned this pull request Nov 12, 2026
perf: convert large Arrow results to rows in slices #1039
Open
4 tasks done

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vuanhphung vuanhphung vuanhphung left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

NaN in FLOAT/DOUBLE columns is returned as None (same as NULL) when pandas is enabled

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@maharanay22 @vuanhphung
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.