Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of strings not displayed in Variable Explorer pane #22570

Open
jitseniesen opened this issue Sep 25, 2024 · 1 comment
Open

Array of strings not displayed in Variable Explorer pane #22570

jitseniesen opened this issue Sep 25, 2024 · 1 comment

Comments

@jitseniesen
Copy link
Member

The array

np.array([[a, b],
          [c, d]])

is displayed as ndarray object of numpy module in the variable explorer (red) instead of listing the values, as would happen for an array of numbers.

spyder6 0 1b

Originally posted by @PhilipYip1988 in #22466 (comment)

@PhilipYip1988
Copy link

I think the memory of a ndarray of text is preallocated from the supplied text data, with 4 bytes used for each Unicode character:

>>> import numpy as np
>>> nums = np.array([[1, 2], [3, 4]])
>>> nums.dtype
dtype('int64')
>>> arr1 = np.array([['a', 'b'],['c' ,'d']])
>>> arr1.dtype
dtype('<U1')
>>> arr5 = np.array([['abcde', 'b'],['c' ,'d']])
>>> arr5.dtype
dtype('<U5')

>>> arr1[0, 0] = 'yellow'
>>> arr1[0, 0]
np.str_('y')

>>> arr5[0, 0] = 'yellow'
>>> arr5[0, 0]
np.str_('yello')

Currently the type shown in Spyder is Array of str32 and Array of str160, it might be clearer if Array of <U1 and Array of <U5 is used, more consistent to the dtype attribute:

Screenshot 2024-09-25 130243

There is slightly inconsistent behaviour when indexing into a numeric array for example of np.int8 and replacing it with a value that is out of the range of the datatype of the array. I think one major change with numpy 2 was to avoid silent truncation for numeric data outlined in NumPy 2.0 Migration Guide and NEP50.

Screenshot 2024-09-25 131727

However it seems that NEP50 isn't implemented for the text data and a silent truncation is still carried out:

Screenshot 2024-09-25 131918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants