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

Using Quantity in np.linspace with option retstep=True raises VisibleDeprecationWarning #1340

Open
mmarras opened this issue Jun 26, 2021 · 1 comment
Labels
numpy Numpy related bug/enhancement

Comments

@mmarras
Copy link

mmarras commented Jun 26, 2021

pint: 0.17
numpy: 1.21.0
python: 3.9.1


Hi,

the docs state that np.linspace is supported by pint, thus maybe this would be nice to have someone looking into.

time = 10 * ureg.s
np.linspace(0, time, num = 50)

is fine, but

np.linspace(0, time, num = 50, retstep=True)

raises

~\site-packages\numpy\core_asarray.py:102:
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
return array(a, dtype, copy=False, order=order)

According to the inet, has to do with a change introduced in numpy 1.19 requiring explicit statment of 'dtype=object' when creating those arrays.

I guess this is a workaround, so is not too critical.

ureg = pint.UnitRegistry()
time = 10 * ureg.s
numpy.linspace(0, time, num=50)
numpy.linspace(0, time.magnitude, num=50, retstep=True)[1] * time.units

But I guess this may not be the only numpy function which does something like this.

@hgrecco hgrecco added the numpy Numpy related bug/enhancement label Jul 8, 2021
@hgrecco
Copy link
Owner

hgrecco commented Jul 8, 2021

Indeed, this was working with numpy 1.18.5 but not with +1.19.

Would you like to submit a PR, take a look at the current generic implementation here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
numpy Numpy related bug/enhancement
Projects
None yet
Development

No branches or pull requests

2 participants