Skip to content

Fix coordinate-bound support and safe partition pruning - #248

Merged
alxmrs merged 2 commits into
xqlsystems:mainfrom
ghostiee-11:fix/coordinate-bounds-121
Sep 7, 2026
Merged

Fix coordinate-bound support and safe partition pruning#248
alxmrs merged 2 commits into
xqlsystems:mainfrom
ghostiee-11:fix/coordinate-bounds-121

Conversation

@ghostiee-11

@ghostiee-11 ghostiee-11 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Adds exact coordinate bounds for numeric, boolean, string, binary, timestamp, and duration types while keeping pruning and statistics conservative and overflow-safe.
Closes #121.

@ghostiee-11

Copy link
Copy Markdown
Contributor Author

@alxmrs Can you review this :)

@alxmrs alxmrs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for supporting all these types.

Comment thread Cargo.toml
pyo3 = { version = "0.28.0", features = ["extension-module", "abi3-py310"] }
# platform works on all CPython >= 3.10 (matching `requires-python`). Maturin
# enables `pyo3/extension-module` through pyproject.toml for wheel builds; it
# must stay disabled for ordinary Cargo test binaries so they link libpython.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for catching this.

Comment thread src/lib.rs

// TODO(alxmrs, Claude): Support every valid xarray coordinate type.
/// Scalar value for dimension bounds, supporting common xarray coordinate types.
/// Scalar value for orderable xarray dimension bounds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Niice

Comment thread src/lib.rs
DurationSecond(i64),
DurationMillisecond(i64),
DurationMicrosecond(i64),
DurationNanosecond(i64),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread src/lib.rs

// Incompatible types
_ => None,
fn integer_bound(bound: &ScalarBound) -> Option<IntegerBound> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we promote to 128 for comparisons, then return back?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, only for the comparison. widening to i128/u128 is so a signed bound and an unsigned one can be ordered without wrapping, and compare_integers just gives back an Ordering. the stored ScalarBound keeps its native width and bound_to_scalar hands it back at the column's own arrow type, so no value round trips through 128.

Comment thread src/lib.rs
let val = obj.extract::<i64>()?;
Ok(ScalarBound::Int64(val))
}
"bool" => Ok(ScalarBound::Boolean(obj.extract::<bool>()?)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice

Comment thread src/lib.rs
TimeUnit::Second if v % 1_000_000_000 == 0 => Some(v / 1_000_000_000),
_ => None,
}?;
(ScalarBound::Utf8(v), DataType::Utf8) => Some(ScalarValue::Utf8(Some(v.clone()))),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice

Comment thread tests/test_df.py


def test_partition_metadata_skips_out_of_ns_datetime():
# datetime64 coordinates outside the datetime64[ns] range (pre-1678 /

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Happy to see this deleted.

Comment thread tests/test_reader.py Outdated
assert result["x"].tolist() == [6, 7]
assert tracker.iteration_count == 1

@pytest.mark.parametrize("dtype", ["float32", "float64"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you import half floats (float16)? If so, it might be good to test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, float16 was only covered at the bound level in test_df.py. added it to the parametrize here and it prunes fine, coord stays halffloat in the arrow schema so it really goes through ScalarBound::Float16. pandas warns about float16 indexes but xarray keeps the variable, so the bound is exact.

Comment thread xarray_sql/df.py
if cft.is_cftime_index(ds, coord_name):
units, calendar = cft.encoding(ds, coord_name)
columns.append(cft.arrow_field(coord_name, units, calendar))
elif isinstance(coord_var.dtype, pd.CategoricalDtype):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm happy we're covering this case.

@ghostiee-11

Copy link
Copy Markdown
Contributor Author

@alxmrs i guess now its good to merge :)

@alxmrs
alxmrs merged commit 9540f0e into xqlsystems:main Sep 7, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support all xarray coordinate types in ScalarBound

2 participants