Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DataManager.copy(None) functionality to a new, dinstinct function #6303

Open
ESadek-MO opened this issue Feb 3, 2025 · 0 comments
Open

Comments

@ESadek-MO
Copy link
Contributor

Suggested for v4.0.0, as this would introduce breaking changes!

Discussed in #6265

Summarized from discussion posted by ESadek-MO December 17, 2024, with contributions from bjlittle and pp-mo

The current behavior of Cube.copy(None) is to copy the cube exactly, without replacing the data.

This no longer fits the contract that will be implemented with #6253, for a few reasons:

  • The current behavior seems to be unique to Iris, most other packages don't offer the choice to replace the data. Ideally, we want to be as accessible as possible, and as such mirroring the pattern found within the Python ecosystem should be a goal (where sensible).
  • Implement dataless cubes #6253 introduces dataless cubes. This means that None means "No data", as opposed to just meaning the absence of anything. This creates a confusing message, Cube(None, shape=(...)) creates a dataless cube, but Cube.copy(None) doesn't remove the data, but maintains it.
  • Also introduced in Implement dataless cubes #6253, is that data in iris.cube.Cube is now a kwarg rather than an arg.

The new idea would be to separate out the replace functionality. So you'd have cube.copy(), which would only create a copy, and cube.replaced() (name undecided) which would use copy, and copy and replace the data.

This would mean Cube.copy would always return the same type of cube i.e., if you give it a cube with data then it will always return a duplicate cube with data, and if you give it a cube without data then it will always return a duplicate cube without data, which is a cleaner, simpler contract.

my_cube = iris.cube.Cube(data=[...])

# would only copy the cube, without changing the data
my_copy = my_cube.copy()

# would copy the cube, and replace the data with [...]
replaced_copy = my_cube.replaced(data=[...])

# would copy the cube, and remove the data
dataless_copy = = my_cube.replaced(data=None)
# or
dataless_copy = = my_cube.replaced()

Some further things to think on:

  • what about other components, e.g. dataless coords ?
  • what about operations on dataless cubes (we need a list of future possibles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant