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

iris.util.new_axis gives odd result if existing dim coord is passed #4415

Closed
rcomer opened this issue Nov 12, 2021 · 0 comments · Fixed by #5194
Closed

iris.util.new_axis gives odd result if existing dim coord is passed #4415

rcomer opened this issue Nov 12, 2021 · 0 comments · Fixed by #5194
Assignees
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development Type: Bug

Comments

@rcomer
Copy link
Member

rcomer commented Nov 12, 2021

🐛 Bug Report

If the scalar coord passed to iris.util.new_axis is already a dimension coordinate, an anonymous new dimension is created.

How To Reproduce

import iris
import iris.cube

print(iris.__version__)

cube = iris.cube.Cube(1)
coord = iris.coords.DimCoord(1, long_name="spam")
cube.add_aux_coord(coord)

new_cube = iris.util.new_axis(cube, coord)
new_new_cube = iris.util.new_axis(new_cube, coord)

for c in [cube, new_cube, new_new_cube]:
    print(c)

output:

3.2.dev0
unknown / (unknown)                 (scalar cube)
    Scalar coordinates:
        spam                        1
unknown / (unknown)                 (spam: 1)
    Dimension coordinates:
        spam                             x
unknown / (unknown)                 (-- : 1; spam: 1)
    Dimension coordinates:
        spam                            -        x

Expected behaviour

I think we should probably get an exception if our "spam" coord is already a dim coord. It might be as simple as adding dim_coords=False in the call to src_cube.coord here:

iris/lib/iris/util.py

Lines 1116 to 1117 in ab1e699

if scalar_coord is not None:
scalar_coord = src_cube.coord(scalar_coord)

Environment

  • OS & Version: RHEL 7.9
  • Iris Version: 3.2.dev0
@rcomer rcomer added Type: Bug New: Issue Good First Issue A good issue to take on if you're just getting started with Iris development labels Nov 12, 2021
@ESadek-MO ESadek-MO moved this to 🆕Potential Tickets in 🐻 Iris v3.5.0 Dec 12, 2022
@ESadek-MO ESadek-MO moved this from 🆕Potential Tickets to 📋 Backlog in 🐻 Iris v3.5.0 Dec 12, 2022
@ESadek-MO ESadek-MO moved this from 📋 Backlog to 🆕Potential Tickets in 🐻 Iris v3.5.0 Dec 12, 2022
@ESadek-MO ESadek-MO moved this from 🆕Potential Tickets to 🔖Assigned in 🐻 Iris v3.5.0 Dec 13, 2022
@scottrobinson02 scottrobinson02 moved this from 🔖Assigned to ✅ Done in 🐻 Iris v3.5.0 Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development Type: Bug
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants