MCPcopy Create free account
hub / github.com/numpy/numpy / DTypePromotionError

Class DTypePromotionError

numpy/exceptions.py:189–231  ·  view source on GitHub ↗

Multiple DTypes could not be converted to a common one. This exception derives from ``TypeError`` and is raised whenever dtypes cannot be converted to a single common one. This can be because they are of a different category/class or incompatible instances of the same one (see Exam

Source from the content-addressed store, hash-verified

187
188
189class DTypePromotionError(TypeError):
190 """Multiple DTypes could not be converted to a common one.
191
192 This exception derives from ``TypeError`` and is raised whenever dtypes
193 cannot be converted to a single common one. This can be because they
194 are of a different category/class or incompatible instances of the same
195 one (see Examples).
196
197 Notes
198 -----
199 Many functions will use promotion to find the correct result and
200 implementation. For these functions the error will typically be chained
201 with a more specific error indicating that no implementation was found
202 for the input dtypes.
203
204 Typically promotion should be considered "invalid" between the dtypes of
205 two arrays when `arr1 == arr2` can safely return all ``False`` because the
206 dtypes are fundamentally different.
207
208 Examples
209 --------
210 Datetimes and complex numbers are incompatible classes and cannot be
211 promoted:
212
213 >>> np.result_type(np.dtype("M8[s]"), np.complex128)
214 DTypePromotionError: The DType <class 'numpy.dtype[datetime64]'> could not
215 be promoted by <class 'numpy.dtype[complex128]'>. This means that no common
216 DType exists for the given inputs. For example they cannot be stored in a
217 single array unless the dtype is `object`. The full list of DTypes is:
218 (<class 'numpy.dtype[datetime64]'>, <class 'numpy.dtype[complex128]'>)
219
220 For example for structured dtypes, the structure can mismatch and the
221 same ``DTypePromotionError`` is given when two structured dtypes with
222 a mismatch in their number of fields is given:
223
224 >>> dtype1 = np.dtype([("field1", np.float64), ("field2", np.int64)])
225 >>> dtype2 = np.dtype([("field1", np.float64)])
226 >>> np.promote_types(dtype1, dtype2)
227 DTypePromotionError: field names `('field1', 'field2')` and `('field1',)`
228 mismatch.
229
230 """
231 pass

Callers 1

_promote_fieldsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected