Skip to content

to_xarray: global_attrs has inconsistent behaviour #786

@pawel-wolff

Description

@pawel-wolff

What happened?

Some types of global attributes specifications in the to_xarray method (global_attrs kwarg) are ignored.

What are the steps to reproduce the bug?

import earthkit.data as ekd

ds_fl = ekd.from_source("sample", "pl.grib")

ds = ds_fl.to_xarray(
    attrs_mode="fixed", 
    global_attrs=[
        {"centre_fixed": "_ecmf_"}, 
        lambda md: {"centre_callable": md.get("centre")}, 
        "centre", 
        "key=centreDescription", 
        {"centre_key": "key=centre"}, 
    ], 
)

ds.attrs

The current output is:

{'centre_callable': 'ecmf', 'centre_fixed': '_ecmf_'}

The excepted output is:

{'centre_callable': 'ecmf',
 'centre': 'ecmf',
 'centreDescription': 'European Centre for Medium-Range Weather Forecasts',
 'centre_key': 'ecmf',
 'centre_fixed': '_ecmf_'}

Version

main, latest (v0.16.1)

Platform (OS and architecture)

all

Relevant log output

Accompanying data

No response

Organisation

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions