Skip to content

Allow scalar data for zero-dim CoordManager and propagate CoordManager dims in PatchAttrs.update#625

Open
d-chambers wants to merge 3 commits intomasterfrom
codex/fix-issue-623
Open

Allow scalar data for zero-dim CoordManager and propagate CoordManager dims in PatchAttrs.update#625
d-chambers wants to merge 3 commits intomasterfrom
codex/fix-issue-623

Conversation

@d-chambers
Copy link
Copy Markdown
Contributor

@d-chambers d-chambers commented Mar 13, 2026

Motivation

  • Ensure a CoordManager with no dimensions accepts scalar data arrays so zero-dim patches can be represented as scalars.
  • Ensure that when a PatchAttrs is updated with a CoordManager, the patch dimensions are updated and subsequent coordinate parsing uses the new dims.

Description

  • In PatchAttrs.update, if coords is a CoordManager then set out["dims"] = passed_in_coords.dims so the model reflects the incoming dims.
  • Update the separate_coord_info call to use tuple(out.get("dims", self.dim_tuple)) so coordinate extraction honors the updated dims.
  • In CoordManager.validate_data, allow scalar data for managers with no dims by returning the scalar when not self.dims and data.shape == ().
  • Add tests test_scalar_data_ok_for_no_dims in tests/test_core/test_coordmanager.py and test_squeeze_all_dims_len_one in tests/test_proc/test_proc_coords.py to cover the new behaviors.

Testing

  • Added unit test test_scalar_data_ok_for_no_dims which asserts a zero-dim CoordManager accepts scalar np.array(1.0) and the test passed.
  • Added unit test test_squeeze_all_dims_len_one which asserts squeezing an aggregated (1,1) patch produces a scalar patch with no dims and the test passed.
  • Ran the related coord manager and patch coordinate tests (coordmanager and proc coord suites) and they completed successfully.

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of scalar/0‑dim data so empty/no-dimension arrays validate and propagate without errors.
    • Ensured externally supplied dimension metadata is respected and applied during coordinate updates and parsing.
  • Tests

    • Added tests validating scalar data acceptance, squeezing to scalar, and correct empty-dimension metadata after reductions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 702b8b0b-0207-45b6-b59d-81d74824127d

📥 Commits

Reviewing files that changed from the base of the PR and between 12366ba and f263521.

📒 Files selected for processing (2)
  • dascore/core/coordmanager.py
  • tests/test_core/test_coordmanager.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • dascore/core/coordmanager.py
  • tests/test_core/test_coordmanager.py

Walkthrough

Propagates CoordManager-provided dims into Patch attrs and uses them to derive coord parsing; adds an early return in CoordManager.validate_data to accept scalar data when no dims exist; adds tests for scalar/no-dim validation and squeeze-to-scalar behavior.

Changes

Cohort / File(s) Summary
Attrs update and coord dims propagation
dascore/core/attrs.py
When kwargs["coords"] is a CoordManager, its dims are propagated into the output attrs and used to derive coord parsing (accepts comma-separated dim strings); coord/attr extraction now prefers output dims over self.dim_tuple.
CoordManager validation
dascore/core/coordmanager.py
validate_data now converts data with np.asarray and returns early when there are no dims and data.shape == (), allowing 0-D arrays/scalars without triggering shape errors.
Tests: coord & squeeze behavior
tests/test_core/test_coordmanager.py, tests/test_proc/test_proc_coords.py
Adds tests for validating numpy and Python scalars against a no-dims CoordManager, and a test ensuring squeezing a (1,1) patch yields scalar data, empty dims, and empty attrs.dim_tuple.

Possibly related PRs

  • fix attr update from coords #527: Modifies PatchAttrs.update to respect CoordManager-provided coordinate info (dims/coords) during attrs update/merge — directly related to dims propagation changes.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: allowing scalar data for zero-dim CoordManager and propagating CoordManager dims in PatchAttrs.update, matching the actual code modifications.
Description check ✅ Passed The PR description comprehensively covers motivation, technical details, testing approach, and test results. It includes relevant context linking to PR #625 and demonstrates thorough testing validation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-issue-623
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added bug Something isn't working proc Related to processing module labels Mar 13, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d6e34dc6d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


coord_info, attr_info = separate_coord_info(kwargs, dims=self.dim_tuple)
coord_info, attr_info = separate_coord_info(
kwargs, dims=tuple(out.get("dims", self.dim_tuple))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve dimension names when deriving dims for attr updates

Wrapping out.get("dims", self.dim_tuple) in tuple(...) here regresses the common case where out["dims"] is a comma-separated string (e.g. "distance,time"), because it becomes a character tuple instead of dimension names. That corrupts dims during PatchAttrs.update and breaks coordinate-field updates such as attrs.update(distance_units="miles") (the distance coord is not updated and dims is rewritten as comma-joined characters).

Useful? React with 👍 / 👎.

Comment on lines +822 to +823
if not self.dims and data.shape == ():
return data
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep shape/size semantics consistent for zero-dim scalars

This early return allows scalar data for empty-dim managers, but CoordManager.shape still reports (0,) when self.dims is empty, so zero-dim patches can now be created with data.shape == () while patch.shape == (0,) and patch.size == 0. That violates the documented Patch shape/size behavior and can mislead downstream code that relies on coords.shape/coords.size after squeeze() or other zero-dim reductions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dascore/core/attrs.py`:
- Around line 244-246: PatchAttrs.update is passing dims through tuple(...)
directly which turns comma-separated strings into character tuples and breaks
separate_coord_info's prefix matching; fix by normalizing dims first (handle
string vs iterable) before converting to a tuple — e.g., detect if
out.get("dims", self.dim_tuple) is a str and split on commas (or otherwise use
the existing iterate() defensive logic) to produce a sequence of full dim names,
then wrap that normalized sequence with tuple(...) when calling
separate_coord_info; update the call site in PatchAttrs.update where dims is
computed so separate_coord_info receives a tuple of full dimension names.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e707e20c-2361-404f-ba21-d316464452d3

📥 Commits

Reviewing files that changed from the base of the PR and between 6d927bc and d6e34dc.

📒 Files selected for processing (4)
  • dascore/core/attrs.py
  • dascore/core/coordmanager.py
  • tests/test_core/test_coordmanager.py
  • tests/test_proc/test_proc_coords.py

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.93%. Comparing base (6d927bc) to head (f263521).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #625      +/-   ##
==========================================
+ Coverage   99.49%   99.93%   +0.44%     
==========================================
  Files         135      135              
  Lines       11570    11576       +6     
==========================================
+ Hits        11511    11568      +57     
+ Misses         59        8      -51     
Flag Coverage Δ
unittests 99.93% <100.00%> (+0.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

bug Something isn't working codex proc Related to processing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant