Description
We found this one with Hypothesis, HypothesisWorks/hypothesis#1963, and I added a workaround at the PyCon sprints but only now got around to opening an upstream issue.
Fields with the empty string as their name are re-named f{index}
; it would be a sufficient fix to detect if there is another field with that as an explicit name and choose something else. The idea would be that the field ... occurs more than once
would only occur if a name was actually specified more than once by the user.
Defaulting to f{index_of_other_use}
would be confusing, and does not cover multiple or multi-step collisions. Any other deterministic name might have to consider number-of-fields options; imagine for example the rule "increment the field number" on names "", "f0", "f1", ...
.
I would therefore also be happy with an improved error message, that The field at index _x_ is named "", which defaults to "f_x_", but this name is already in use at index _y_.
.
Reproducing code example:
import numpy as np
# raises `ValueError: field 'f0' occurs more than once`
np.dtype([("", int), ("f0", int)])
# Forecloses the easy "swap the names" solution
np.dtype([("", int), ("f0", int), ("f1", int)])
Numpy/Python version information:
Numpy 1.14.5 and 1.17.0; Python 3.7 and earlier.