Skip to content

.values[()] in _get_unfiltered_pkg_options should be .item()? #1682

@Huite

Description

@Huite

In fetching options, .values[()] is used:

    def _get_unfiltered_pkg_options(
        self, predefined_options: dict, not_options: Optional[list] = None
    ):
        options = copy(predefined_options)

        if not_options is None:
            not_options = []
            if hasattr(self, "_period_data"):
                not_options.extend(self._period_data)
            if hasattr(self, "_auxiliary_data"):
                not_options.extend(self._auxiliary_data.keys())

        for varname in self.dataset.data_vars.keys():  # pylint:disable=no-member
            if varname in not_options:
                continue
            v = self.dataset[varname].values[()]
            options[varname] = v
        return options

Unless I'm mistaken, options should always be scalar. So I think .item() should be used instead.

.item() has the strong advantage of erroring on non-scalar contents. At the moment, the concentration array is fully loaded into memory due to #1681; this would not have happened if .item() is used here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    📯 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions