Skip to content

Enable unc_comps to be string as well as list #15

Open

Description

@madsted

Some obsarray functionality raises an error for uncertainty variables where the unc_comp attribute is a string rather than a list. This can arise when there is only one uncertainty component for a variable. Obsarray should be able to handle unc_comps as a list or a string.

e.g.
line run:

del ds.unc[obs_var][var]

error:
Traceback (most recent call last):
File "C:\Users\mes\Anaconda3\envs\eoio\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
del ds.unc[obs_var][var]
File "c:\users\mes\code\pycharmprojects\obsarray\obsarray\unc_accessor.py", line 424, in delitem
self._obj.unc._remove_unc_var(self._var_name, unc_var)
File "c:\users\mes\code\pycharmprojects\obsarray\obsarray\unc_accessor.py", line 898, in _remove_unc_var
self._obj[obs_var].attrs["unc_comps"].remove(unc_var)
AttributeError: 'str' object has no attribute 'remove'

Activity

  1. shunt16 commented on Oct 27, 2026

    @shunt16
    Collaborator

    Still an issue for del ds.unc[obs_var][unc_var], which fails with AttributeError: 'str' object has no attribute 'remove' when unc_comps is a string.

    Also found that ds.unc.rename breaks a string unc_comps (i.e. a variable with a single uncertainty component) - e.g. ds.unc.rename({"u_temperature": "u_t2"}) leaves unc_comps as ['u', '_', 't', 'e', 'm', ...], the characters of the old name, rather than renaming it.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions