Skip to content

[pwnlayers3] REGIS-completeness guard raises an inscrutable pandas error in the case it was written for #65

Description

@bdestombe

pwnlayers3/layers.py:147:

if (ds_regis.layer != nlmod.read.regis.get_layer_names()).any():
    msg = "All REGIS layers should be present in \`ds_regis\`. Use \`get_regis(.., remove_nan_layers=False)\`."
    raise ValueError(msg)

The comparison is elementwise, so it only works when the two layer indexes have the same length. When ds_regis is missing a layer — precisely what get_regis(remove_nan_layers=True) produces, and precisely what this guard exists to catch — the comparison raises first:

ValueError: Lengths must match to compare

The user gets a pandas internals error instead of the actionable message telling them to pass remove_nan_layers=False. The guard fires correctly only in the unlikely case where the layer count matches but the names differ.

Reproduced while writing the test suite:

ds_regis = ds_regis.sel(layer=REGIS_LAYERS[:-1])   # drop one layer
get_pwn_layer_model(ds_regis=ds_regis, ...)        # -> "Lengths must match to compare"

Suggested fix — compare as sets/sequences rather than elementwise:

expected = list(nlmod.read.regis.get_layer_names())
if list(ds_regis.layer.values) != expected:
    raise ValueError(msg)

The test for this guard is committed as xfail(strict=True) referencing this issue, so it will turn into a visible XPASS the moment the guard is fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions