Skip to content

Add Patch.squeeze_coords - #995

Open
d-chambers wants to merge 3 commits into
devfrom
squeeze-coords
Open

Add Patch.squeeze_coords#995
d-chambers wants to merge 3 commits into
devfrom
squeeze-coords

Conversation

@d-chambers

@d-chambers d-chambers commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Description

Adds Patch.squeeze_coords, which converts non-dimensional coordinates holding a single value into patch attributes.

A coordinate whose values are all the same says one thing about the patch rather than one thing about each sample. squeeze_coords drops each such coordinate and stores its value in the attrs under the coordinate's name:

patch = patch.update_coords(quality=("distance", np.ones(n)))

patch.squeeze_coords()           # every non-dim coord which qualifies
patch.squeeze_coords("quality")  # or only the ones named

It complements Patch.squeeze, which removes length one dimensions: squeeze_coords never touches a dimension, so patch.squeeze_coords().squeeze() keeps what a bare squeeze() would throw away (dropping a dimension drops the coordinates which depend on it).

Details:

  • Naming a coordinate which is a dimension, is not in the patch, or does not hold exactly one non-null value raises CoordError. The unnamed sweep passes over those instead, and an empty selection (squeeze_coords([])) does nothing.
  • Coordinate units are not kept, only the value. Times stay np.datetime64; every other value is stored as a python scalar.
  • A null value (NaN or NaT) is not a value to state, so an all-null or partial coordinate is left alone.
  • The five attr names the patch machinery owns (coords, dims, history, patch_id, processing_id) cannot hold a coordinate's value — dims is dropped by PatchAttrs.from_dict, coords is refused there, and the last three are stamped over by the patch_function decorator after the body returns. A coordinate named for one of them is skipped by the sweep and refused when named.
  • A patch with nothing to squeeze is handed back unchanged.

tests/test_workflow/_calls.py gains a catalogued call, which TestEveryPatchFunction requires of every patch function.

Changelog

  • added: Patch.squeeze_coords converts non-dimensional coordinates which hold a single value into patch attributes.

Checklist

I have:

  • filled in the Changelog section above (see docs/contributing/general_guidelines.qmd).

I have (if applicable):

  • referenced the GitHub issue this PR closes.
  • documented the new feature with docstrings and/or appropriate doc page.
  • included tests. See testing guidelines.
  • added the "ready_for_review" tag once the PR is ready to be reviewed.

Summary by CodeRabbit

  • New Features

    • Added squeeze_coords to convert single-value, non-dimensional coordinates into patch attributes.
    • Supports selecting specific coordinates or automatically processing eligible coordinates.
    • Preserves coordinate values across string, datetime, numeric, and unit-based data.
  • Documentation

    • Added a tutorial example demonstrating coordinate squeezing.
  • Bug Fixes

    • Added validation for invalid, empty, multi-valued, dimensional, and reserved-name coordinates.

Convert non-dimensional coordinates which hold a single value into patch
attributes, leaving length one dimensions to Patch.squeeze.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@d-chambers, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f014136a-3835-441c-ae6b-d6a7e50f55a7

📥 Commits

Reviewing files that changed from the base of the PR and between 8d5affb and e13be9d.

📒 Files selected for processing (3)
  • dascore/proc/coords.py
  • docs/tutorial/processing.qmd
  • tests/test_proc/test_proc_coords.py

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41858e48-b0b9-4acf-ba32-41b430f919a0

📥 Commits

Reviewing files that changed from the base of the PR and between 5d1d149 and 8d5affb.

📒 Files selected for processing (5)
  • dascore/core/patch.py
  • dascore/proc/coords.py
  • docs/tutorial/processing.qmd
  • tests/test_proc/test_proc_coords.py
  • tests/test_workflow/_calls.py

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

The PR adds Patch.squeeze_coords and the underlying coordinate operation. Single-valued non-dimensional coordinates move to patch attributes. Validation covers coordinate types, reserved names, null values, dimensions, and no-op cases. Documentation and workflow coverage are included.

Coordinate squeezing

Layer / File(s) Summary
Coordinate extraction and validation
dascore/proc/coords.py
Adds lone-value extraction, reserved attribute checks, coordinate validation, and squeeze_coords. Qualifying coordinates are dropped and their values are merged into patch attributes.
Public API and validation coverage
dascore/core/patch.py, dascore/proc/coords.py, docs/tutorial/processing.qmd, tests/test_proc/test_proc_coords.py, tests/test_workflow/_calls.py
Exposes Patch.squeeze_coords, documents its behavior, and tests direct and workflow usage across supported types and invalid or empty cases.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the primary change: adding Patch.squeeze_coords.
Description check ✅ Passed The description explains the feature, documents behavior, lists changelog details, and confirms documentation and test coverage.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 4 files. (1 skipped: 1 unsupported.)
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch squeeze-coords

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.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5d1d149) to head (e13be9d).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #995   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          202       202           
  Lines        27343     27406   +63     
=========================================
+ Hits         27343     27406   +63     
Flag Coverage Δ
network 39.17% <15.87%> (-0.06%) ⬇️
unittests 100.00% <100.00%> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

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

Copy link
Copy Markdown

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: 8d5affb0f3

ℹ️ 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".

Comment thread dascore/proc/coords.py Outdated
return _NO_VALUE
values = np.asarray(coord.values).reshape(-1)
value = values[0]
if values.size > 1 and not bool(np.all(values == value)):

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 Check null values before comparing the full coordinate

When a non-dimensional CoordPartial is large, coord.values is a cheap broadcasted null view, but values == value creates and scans a coordinate-sized boolean array before the following null check rejects it. Calling the default squeeze_coords() on a patch with a large partial coordinate can therefore consume substantial memory or OOM even though the coordinate is known immediately to have no value; check the first value for nullness before performing the array-wide equality comparison.

Useful? React with 👍 / 👎.

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.

Fixed in e13be9d: the nullish check now runs before the array-wide comparison, so a partial coord is rejected off its first value without materializing a coord-sized boolean array.

Comment thread dascore/proc/coords.py Outdated
Comment on lines +1035 to +1036
attrs = self.attrs.model_dump(exclude_unset=True) | values
return self.new(coords=new_coords, attrs=attrs)

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 Preserve the patch's specialized attrs class

When the input comes from a format that supplies a PatchAttrs subclass, such as ODH4PatchAttrs, dumping the attrs to a plain dict causes self.new to reconstruct them as the base PatchAttrs. Thus squeezing an otherwise ordinary coordinate silently discards the format-specific attrs type and its validation behavior; update the existing attrs model (or otherwise reconstruct through its concrete class) instead of passing a plain mapping.

Useful? React with 👍 / 👎.

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.

Fixed in ec7f3db: the merge now goes through PatchAttrs.update, which rebuilds through self.from_dict, so the concrete class is kept (Patch.update then passes a PatchAttrs instance straight through). Pinned by test_attrs_class_kept.

Refuse to squeeze a coordinate the patch is not free to state: a private
one, one a transform needs to invert itself, one named for something the
attrs already use, and values the attrs cannot hold (object, complex,
null). Reuse PatchAttrs.update for the merge and get_coord's message for
a missing name, and treat a None argument as no argument.
@d-chambers d-chambers added the ready_for_review PR is ready for review label Aug 22, 2026
Check for a null value before the array-wide comparison, and pin that a
format's own attrs class survives the squeeze.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready_for_review PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant