Skip to content

zip_array_values and zip_array_items fail for axes=() #883

@gdementen

Description

@gdementen

This matters mostly when using those functions to build other functions. I had to inline a copy of zip_array_values to do ols in "PLUS" to fix this issue:

def _zip_array_values(values, axes=None, ascending=True):
    def values_with_expand(value, axes, readonly=True, ascending=True):
        if isinstance(value, Array):
            # an Axis axis is not necessarily in array.axes
            expanded = value.expand(axes, readonly=readonly)
            return expanded.values(axes, ascending=ascending)
        else:
            size = axes.size if axes.ndim else 0
            return Repeater(value, size)

    # empty axes list, return values themselves
    if axes is not None and not axes:
        return [values]

    values_axes = [get_axes(v) for v in values]

    if axes is None:
        all_iter_axes = values_axes
    else:
        if not isinstance(axes, (tuple, list, AxisCollection)):
            axes = (axes,)

        # transform string axes _definitions_ to objects
        axes = [Axis(axis) if isinstance(axis, str) and '=' in axis else axis
                for axis in axes]

        # get iter axes for all values and transform string axes _references_ to objects
        all_iter_axes = [AxisCollection([value_axes[axis] for axis in axes if axis in value_axes])
                         for value_axes in values_axes]

    common_iter_axes = AxisCollection.union(*all_iter_axes)

    # sequence of tuples (of scalar or arrays)
    return SequenceZip([values_with_expand(v, common_iter_axes, ascending=ascending) for v in values])

(and for the new version of ols in PLUS I needed zip_array_items but I was too lazy to fix it too and did an awful workaround)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions