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: Allow defining array(s) on construction #6104

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Aug 30, 2023

Currently, the constructor does not allow to define any arrays to set
when constructing a new node, so one is forced to multi line code:

node = XyData()
node.set_x(np.array([1, 2]), 'name', unit')
node.set_y(np.array([3, 4]), 'name', unit')

This commit allows initialization upon construction simplifying the code
above to:

node = XyData(
    np.array([1, 2]),
    np.array([3, 4]),
    x_name='name',
    x_unit='unit',
    y_names='name',
    y_units='unit'
)

The units and names are intentionally made into keyword argument only
in order to prevent accidental swapping of values.

For backwards compatibility, it remains possible to construct an
XyData without any arrays.

@sphuber sphuber force-pushed the feature/xy-data-constructor branch from d517ad7 to 46232e0 Compare August 30, 2023 20:11
@sphuber
Copy link
Contributor Author

sphuber commented Sep 5, 2023

Any objections to this @mbercx @unkcpz ?

@unkcpz
Copy link
Member

unkcpz commented Sep 5, 2023

Sorry for the late reply. All good to me, but I didn't use this data type so can't say more.

Currently, the constructor does not allow to define any arrays to set
when constructing a new node, so one is forced to multi line code:

    node = XyData()
    node.set_x(np.array([1, 2]), 'name', unit')
    node.set_y(np.array([3, 4]), 'name', unit')

This commit allows initialization upon construction simplifying the code
above to:

    node = XyData(
        np.array([1, 2]),
        np.array([3, 4]),
        x_name='name',
        x_unit='unit',
        y_names='name',
        y_units='unit'
    )

The units and names are intentionally made into keyword argument only
in order to prevent accidental swapping of values.

For backwards compatibility, it remains possible to construct an
`XyData` without any arrays.
@sphuber sphuber force-pushed the feature/xy-data-constructor branch from 46232e0 to cc87441 Compare September 5, 2023 15:18
@sphuber sphuber merged commit f11598d into aiidateam:main Sep 5, 2023
10 checks passed
@sphuber sphuber deleted the feature/xy-data-constructor branch September 5, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants