Skip to content

drop_coordinates behaviour contradicts documentation #3353

Description

@gerritholl

Describe the bug

According to the documentation, satpy.composites.core.CompositeBase.drop_coordinates drops coordinates that do not correspond to any dimension:

"""Drop negligible non-dimensional coordinates.
Drops negligible coordinates if they do not correspond to any
dimension. Negligible coordinates are defined in the
:attr:`NEGLIGIBLE_COORDS` module attribute.
Args:
data_arrays: Arrays to be checked

In reality, it also drops coordinates that do correspond to a dimension.

To Reproduce

import numpy as np
import xarray as xr
import satpy.composites.core

ds = xr.DataArray(
        np.arange(3*4).reshape(3, 4),
        dims=("y", "x"),
        coords={"time": xr.DataArray(
            np.arange(3).reshape(3), dims=("y",))})

print(ds.coords)

# this dataset has a coordinate (time) corresponding to a dimension (y)

ds_new = satpy.composites.core.CompositeBase.drop_coordinates([ds])[0]

# but the coordinate is still dropped

print(ds_new.coords)

Expected behaviour

I'm not sure what the intention is of the code.

I expect that either

  • the documentation accurate describes that coordinates are dropped even if they correspond to a dimension, unless that dimension has the same name as the coordinate, or
  • this coordinate is retained, as is documented.

Actual results

The coordinate is dropped:

Coordinates:
    time     (y) int64 24B 0 1 2
Coordinates:
    *empty*

Environment Info:

  • OS: openSUSE Leap 15.6
  • Satpy Version: v0.60.0

Additional context

This behaviour was originally introduced in #796. It breaks #3168, which intends to retain time information.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions