Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XyData does not behave as expected #6731

Open
mbercx opened this issue Jan 27, 2025 · 3 comments · May be fixed by #6736
Open

XyData does not behave as expected #6731

mbercx opened this issue Jan 27, 2025 · 3 comments · May be fixed by #6736

Comments

@mbercx
Copy link
Member

mbercx commented Jan 27, 2025

Describe the bug

The behaviour of XyData is not what one would expect when specifying multiple (or even a single) array(s). It is also not in line with the documentation:

https://aiida.readthedocs.io/projects/aiida-core/en/stable/topics/data_types.html#xydata

Steps to reproduce

from aiida import orm, load_profile

load_profile()

import numpy as np

xy = orm.XyData()

xy.set_x(np.array([1, 2, 3]), 'x', 'unit_x')
xy.set_y(np.array([1, 2, 3]), 'y', 'unit_y')
xy.set_y(np.array([1, 2, 3]), 'z', 'unit_z')

print(xy.get_arraynames())
print(xy.get_y())

Gives output:

['x_array', 'y_array_0']
[('z', array([1, 2, 3]), 'unit_z')]

Expected behavior

  1. The arraynames should respect the names I specify in the set_x and set_y commands.
  2. It should be possible to have multiple "y" arrays in one XyData. Here it seems it is overridden (without warning).

Your environment

  • Operating system [e.g. Linux]: macOS
  • Python version [e.g. 3.7.1]: 3.10.16
  • aiida-core version [e.g. 1.2.1]: 2.6.3

EDIT: Also tested on latest origin/main.

@mbercx
Copy link
Member Author

mbercx commented Jan 27, 2025

Ah, it seems I misunderstood the behaviour of set_y, since it's not the same as set_x. You need to set all y arrays in one execution of set_y, and cannot set them one by one.

I suppose we can just make this a documentation issue then, because it was not intuitive to me.

EDIT: Proper example of usage:

from aiida import orm, load_profile

load_profile()

import numpy as np

xy = orm.XyData()

xy.set_x(np.array([1, 2, 3]), 'x', 'unit_x')
xy.set_y([np.array([1, 2, 3]),np.array([4, 5, 6])], ['y', 'z'], ['unit_y', 'unit_z'])

print(xy.get_arraynames())
print(xy.get_y())

Results in:

['x_array', 'y_array_0', 'y_array_1']
[('y', array([1, 2, 3]), 'unit_y'), ('z', array([4, 5, 6]), 'unit_z')]

I would still expect get_arraynames() to return the array names provided to the set_x and set_y methods.

@ayushjariyal
Copy link
Contributor

@mbercx Is this issue still open?

@ayushjariyal ayushjariyal linked a pull request Jan 29, 2025 that will close this issue
@mbercx
Copy link
Member Author

mbercx commented Jan 30, 2025

@mbercx Is this issue still open?

It is, cheers for working on the docs. I'm travelling tomorrow, so a bit busy atm, but will try and have a look at your PR next week! 👍

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

Successfully merging a pull request may close this issue.

2 participants