Fixed bug related to selection keyword argument in get_parity_data

Problem

Calling get_parity_data with flatten=True and a selection that covers fewer components than the full set raised a ValueError when constructing the DataFrame:

df = get_parity_data(structures, 'stress', flatten=True, selection=['xx', 'yy', 'zz'])
# ValueError: All arrays must be of the same length

The component column was built by dividing the length of the flattened target list by the full component count (6 for stress/virial, 3 for force/atomic_v, 9 for bec). With a partial selection the flattened list is shorter, so the division underflowed to zero and the column became empty while target/predicted were not.

Fix

When a selection is active, use len(selection) as the divisor and repeat the selection labels instead of the default full-component labels. The fallback to the default labels is preserved when no selection is given. The same fix is applied to all three affected branches (force/atomic_v, virial/stress, bec).

Tests

Added test_get_parity_data_flatten_with_selection.

Each case asserts that the DataFrame is created without error, that all three columns (target, predicted, component) have equal length, that the row count equals n_structures × len(selection), that the component labels cycle through the selection in order, and that target/predicted are float64.

Merge request reports

Loading