Repository navigation
BUG: reject inconsistent converters to StringDType - #20762
neutrinoceros wants to merge 3 commits into
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
| # Infer converter type from an instance of numpy_type. | ||
| type_name = np.array([], dtype=numpy_type).dtype.name |
There was a problem hiding this comment.
This line is dead now and the comment also doesn't match the code now.
| converter_type = FloatType | ||
| case "b": | ||
| converter_type = BoolType | ||
| case "U": |
There was a problem hiding this comment.
| case "U": | |
| case "U" | "T": |
If we are doing this then it probably makes sense to treat "T" as string-like. For instance:
lines = ["a\tb", "S\tN", "x\t1", "y\t2"]
ascii.read(lines, format="rdb", converters={"b": [ascii.convert_numpy(str)]}) # StrType: rejected -> guess failure
ascii.read(lines, format="rdb", converters={"b": [ascii.convert_numpy("T")]}) # AllType: accepted -> StringDType column
There was a problem hiding this comment.
I'm not sure I understand your suggestion fully.
Here's what I'm grasping:
- the str converter rejects the data
- converting to
StringDTypehowever returns a result that to me looks valid
your suggestion would make both converters fail. I guess that's one way to resolve API inconsistencies, but I don't understand why that would be the behavior we expect. From where I'm standing, it actually looks like the str converter should be able to convert without raising here. Clearly we are not reaching the same conclusion, so am I missing anything ?
There was a problem hiding this comment.
In this case the RDB format specifies that column b is numeric via the N (the "S\tN") line. That type requirement from the file is inconsistent with the user request to treat the column as string and gets rejected with an exception.
This behavior is consistent with the design philosophy / intent of io.ascii that the file format can specify the allowed type(s) and the user can only narrow those types, not go outside.
There was a problem hiding this comment.
ah, I see. That makes a lot of sense, I just wasn't aware of the meaning caried by the second line.
832fcfc to
bebc190
Compare
bebc190 to
14b9cf3
Compare
|
@taldcroft with your suggestion taken into account, the scope changed a bit and this now is a bugfix. I've applied backport labels but if you think that's too disruptive for a backport I think it's also fine not to. Up to you. |
I don't honestly think this would affect any code, but you can probably guess that this falls in the category of a behavior change that I'd rather not backport. I left the milestone at 8.1 and took off the backport labels. Thanks |
|
CI jobs that failed on network errors were rerun and passed. Is there anything else to do before this can be merged ? |
taldcroft
left a comment
There was a problem hiding this comment.
This is basically good but just a couple of non-code fixes.
| Exact example from #9701: When using ascii.read with both the names and | ||
| converters arguments, the converters dictionary ignores the user-supplied | ||
| Adapted from #9701: When using ascii.read with both the names and | ||
| converters arguments, the converters dictionary ignores the user-supplied converters arguments, the converters dictionary ignores the user-supplied |
| @@ -1005,17 +1005,18 @@ def convert_numpy(numpy_type): | |||
| the required type. | |||
| """ | |||
| # Infer converter type from an instance of numpy_type. | |||
There was a problem hiding this comment.
This comment is no longer correct, please update.
Description
Salvaged from gh-20744
The test already passes on main. However, I'm still including a companion refactor to avoid brittle substring matching
(the existing code would have broken when
StringDTypewas introduced in numpy 2 if the class name had beenstringdtype, for instance)AI Disclosure
N/A
Merge method