Skip to content

passing a single Session to stack leads to unexpected result #1057

@gdementen

Description

@gdementen
>>> mul2 = ndtest(3) * 2
>>> mul2
a  a0  a1  a2
    0   2   4
>>> mul10 = ndtest(3) * 10
>>> mul10
a  a0  a1  a2
    0  10  20
>>> sess = Session(mul2=mul2, mul10=mul10)
>>> stack(sess, 'array=mul10,mul2')
a\array  mul10  mul2
     a0      0     0
     a1      2    10
     a2      4    20

The problem is that sess is just seen as an iterable in this case, so is taken as a list, discarding its labels.

I knew it was not implemented (see discussion in #180) but I did not realize that the fact that it seemed to work can lead to silent data garbage when users use this and do not realize the labels do not correspond to the correct data anymore.

I think that fixing this is simply a matter of adding the following lines to stack:

    elif isinstance(elements, Session):
        items = elements.items()

We might want to have a default axis name in that case:

        if axes is None:
            axes = 'array'

but I am unsure about this, and if we go down that path, we should have "sensible" default labels in other places too.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions