This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / promote_types

built-in

numpy:promote_types

Signature

built-in promote_types ( type1 type2 / )

Summary

Returns the data type with the smallest size and smallest scalar kind to which both type1 and type2 may be safely cast. The returned data type is always considered "canonical", this mainly means that the promoted dtype will always be in native byte order.

Extended Summary

This function is symmetric, but rarely associative.

Parameters

type1 : dtype or dtype specifier

First data type.

type2 : dtype or dtype specifier

Second data type.

Returns

out : dtype

The promoted data type.

Notes

Please see numpy.result_type for additional information about promotion.

Starting in NumPy 1.9, promote_types function now returns a valid string length when given an integer or float dtype as one argument and a string dtype as another argument. Previously it always returned the input string dtype, even if it wasn't long enough to store the max integer/float value converted to a string.

NumPy now supports promotion for more structured dtypes. It will now remove unnecessary padding from a structure dtype and promote included fields individually.

Examples

import numpy as np
np.promote_types('f4', 'f8')
np.promote_types('i8', 'f4')
np.promote_types('>i8', '<c8')
np.promote_types('i4', 'S8')
An example of a non-associative case:
p = np.promote_types
p('S', p('i1', 'u1'))
p(p('S', 'i1'), 'u1')

See also

can_cast
dtype
result_type

Aliases

  • numpy.promote_types

Referenced by