GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — BUG: `StringDType(coerce=...)` is not preserved by binary ufuncs when operands differ · Issue #31861 · numpy/numpy Closed Labels DescriptionDescribe the issue:Brief description of bug Binary operations on When two arrays with different The result should enable coercion only when both input dtypes have
StringDType() True
StringDType(coerce=False) False Why its incorrect The result reports Note that behavior is order-dependent for ufuncs: Debugging hints
dtype1->coerce && dtype2->coerce The remaining bug is in the binary ufunc path: @@ -248,7 +248,7 @@ binary_resolve_descriptors(...) { PyArray_StringDTypeObject *descr1 = (PyArray_StringDTypeObject *)given_descrs[0]; PyArray_StringDTypeObject *descr2 = (PyArray_StringDTypeObject *)given_descrs[1]; - int out_coerce = descr1->coerce && descr1->coerce; + int out_coerce = descr1->coerce && descr2->coerce; PyObject *out_na_object = NULL; So the result dtype depends only on the first input’s Applying that one-line change produces the expected result: StringDType(coerce=False) False and assigning a non-string value correctly raises If this is confirmed to be a bug, I'd be happy to contribute a fix Reproduce the code example:import numpy as np from numpy.dtypes import StringDType a = np.array(["a"], dtype=StringDType(coerce=True)) b = np.array(["b"], dtype=StringDType(coerce=False)) c = np.add(a, b) print(c.dtype) # currently: StringDType() print(c.dtype.coerce) # currently: True; expected: False c[0] = object() # currently succeeds (stringifies); should raise ValueError Error message:No exception is raised. If the resulting dtype preserved coerce=False, assigning a non-string value would raise: ValueError: StringDType only allows string data when string coercion is disabled. Python and NumPy Versions:Runtime Environment:How does this issue affect you or how did you find it:No response Activity
MetadataMetadataAssigneesLabelsTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |