Skip to content

Conversation

@dcherian
Copy link
Contributor

@dcherian dcherian commented Dec 4, 2025

Fixes some severe bugs noticed downstream in rasterix

Disclaimer: had lots of help from Claude in writing the strategies but I have reviewed them closely

dcherian and others added 2 commits December 3, 2025 19:44
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dcherian dcherian requested review from benbovy and keewis December 4, 2025 04:09
@github-actions github-actions bot added topic-indexing topic-testing topic-hypothesis Strategies or tests using the hypothesis library labels Dec 4, 2025
The return statement was incorrectly indented inside the for loop,
causing only the first coordinate to be assigned to the DataArray.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Member

@benbovy benbovy left a comment

Choose a reason for hiding this comment

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

Thanks @dcherian!

I haven't reviewed the tests (I'm not very familiar with hypothesis) but the fix looks good to me!

* main:
  Document limitations of cftime arithmetic (pydata#10653)
  Remove RTD htmlzip output format (pydata#10977)
  Support decoding unsigned integers to timedelta (pydata#10972)
  Use `._data` in `Variable._replace` (pydata#10969)
  small changes to the pixi env definitions (pydata#10976)
  Add GitHub Codespaces config for Pixi (pydata#10929)
  Fix workflow name to embed `matrix.pytest-addopts` (pydata#10970)
@dcherian dcherian added the plan to merge Final call for comments label Dec 4, 2025
Copy link
Collaborator

@keewis keewis left a comment

Choose a reason for hiding this comment

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

I think there's a logic error in your tests, so it might be good to resolve that before merging

Comment on lines +26 to +30
def forward(self, dim_positions: dict[str, Any]) -> dict[Hashable, Any]:
return {name: dim_positions[name] for name in self.coord_names}

def reverse(self, coord_labels: dict[Hashable, Any]) -> dict[str, Any]:
return {dim: coord_labels[dim] for dim in self.dims}
Copy link
Collaborator

@keewis keewis Dec 5, 2025

Choose a reason for hiding this comment

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

not sure if I'm misunderstanding something here, but there appears to be something wrong: why do we use coordinate names to index dim_positions (which I think map dimension names to positions), and dimension names to index coord_labels?

(the example at https://xarray-indexes.readthedocs.io/blocks/transform.html#example-astronomy appears to support my mental model of the coordinate transform)

Comment on lines +48 to +51
for dim, size in sizes.items():
transform = IdentityTransform([dim], {dim: size}, dtype=np.dtype(np.int64))
index = CoordinateTransformIndex(transform)
ds = ds.assign_coords(xr.Coordinates.from_xindex(index))
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if this will make this more readable (it does remove the emulated in-place assignment, at least), but it is possible to collect the coordinate objects and then use functools.reduce(operator.or_, coordinates) to merge them together.

microseconds_offset = draw(st.integers(0, timespan_microseconds))

return min_value + datetime.timedelta(microseconds=microseconds_offset)

Copy link
Collaborator

Choose a reason for hiding this comment

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

these are neat, I remember looking for strategies like this before

----------
draw : callable
The Hypothesis draw function (automatically provided by @st.composite).
sizes : dict[Hashable, int]
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure how important this is, but napoleon will not parse these correctly, so we won't get links. This would work, though:

Suggested change
sizes : dict[Hashable, int]
sizes : mapping of hashable to int

and the same for the instances below

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

Labels

plan to merge Final call for comments topic-hypothesis Strategies or tests using the hypothesis library topic-indexing topic-testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants