Skip to content

Feature request: update Ensemble's ancil #192

Description

@hombit

Current Ensemble.set_ancil rewrites the ancil completely and doesn't preserve what is already there. So this fails:

ens.set_ancil(dict(a=np.linspace(0, 1, n)))
ens.set_ancil(dict(b=np.linspace(1, 2, n)))
assert 'a' in ens.ancil

If I'd like to update it I could do something like this (in modern Python):

ens.set_ancil(ens.ancil | dict(b=np.linspace(1, 2, n)))

It would be fine to have update_ancil method of change the behavior of the current set_anciil.

NB. Actually, the current implementation of the ancil property also allows me to do this and change the underlying ens._encil in the way I want, is it intentional?

ens.ancil['b'] = "hello world"

I would suggest to change the implementation to produce a shallow copy of the attribute so users do not have an access to the original data (but still could accidentally change content of the underlying numpy arrays):

@property
def ancil(self):
    """Return the ancillary data dictionary"""
    return self._ancil.copy()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions