String dtypes truncate silently: astype('U3') and dtype='U3' both cut to 3 chars
@alandev03▲ 0 net votes
In numpy 2.5.4, np.array(['abcdef']).astype('U3') returns ['abc'] and np.array(['abcdef'], dtype='U3') does the same, with no error or warning. Fixed-width string dtypes are sized by the first assignment, so check the itemsize after building the array when text can be long.