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

actually fix numpy str type deprecation #634

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

hellkite500
Copy link
Contributor

The fix in #623 served only to mute the module attribute/reference issue of numpy.str being deprecated. The numpy.dtype.str isn't a suitable replacement of numpy.str, as the str attribute here, according to the docs, is

attribute

dtype.str
The array-protocol typestring of this data-type object.

which is not a compatible string datatype. The below error seen when using this as a dtype has been similarly reported while trying to run t-route since merging #623.

It seems that native python types are reasonably supported, though they may not be the most efficient. Using str for the astype arg should work, as seen below, this converts to a unicode string.

Successfully installed numpy-1.25.2
(venv) nelsfrazier@Lynkers-MBP t-route % python
Python 3.11.4 (main, Jul 25 2023, 17:36:13) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> test = np.zeros(2)
>>> test
array([0., 0.])
>>> test.dtype
dtype('float64')
>>> test.astype(np.dtype.str)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot interpret '<attribute 'str' of 'numpy.dtype' objects>' as a data type
>>> test.astype(str)
array(['0.0', '0.0'], dtype='<U32')

I believe this should close #616 with the default unicode string conversion.

@shorvath-noaa shorvath-noaa self-requested a review August 15, 2023 14:37
@shorvath-noaa shorvath-noaa merged commit 97a4df7 into NOAA-OWP:master Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numpy np.str FutureWarning
2 participants