question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`np.float64(np.nan) % 1` gives warning

See original GitHub issue

The following operations correctly return nan without warning:

import numpy as np

np.nan + 1
np.nan - 1
np.nan * 1
np.nan / 1
np.nan % 1

So do

np.float64(np.nan) + 1
np.float64(np.nan) - 1
np.float64(np.nan) * 1
np.float64(np.nan) / 1

Taking %, however, does give a warning:

np.float64(np.nan) % 1
<ipython-input-49-4b0062698971>:1: RuntimeWarning: invalid value encountered in double_scalars
  np.float64(np.nan) % 1

This inconsistency extends to all numpy float types.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
arubialescommented, Feb 7, 2021

@seberg Yes of course. It’s my first contribution to Numpy and after all the hours I want to finish the job properly. I didn’t enter in the .src files because I thought it was for Windows SO only…

I have done similar changes to the file to avoid the warning and I get to avoid with NaN as a second input. Right now I will do:

  • Think the perfect way to do it (now it is a draft)
  • Do the same with np.inf to avoid also the error with this constant.

Thank you very much for your help.

1reaction
sebergcommented, Jan 23, 2021

@arubiales if the warning is actually manually set, it would be something like npy_set_floatstatus. But most likely the opposite is the case: The C code (machine code), sets an error flag (the CPU does this, or well, the basic math library) for a certain operation. And our code would have to avoid taking that code path alltogether.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do negative numpy.float64 yield nan when expontiated ...
A negative numpy.float64 exponentiated with a fractional (i.e., decimal, i.e., rational) number will yield a nan result and a warning.
Read more >
data type conversion of numpy array containing NaN #21364
I am working on floating FPEs given by the CPU/C for these casts, so at least most should give an "invalid value" warning...
Read more >
Working with missing data - Pandas
Warning. One has to be mindful that in Python (and NumPy), the nan's don't compare equal, but None's do. Note that pandas/NumPy uses...
Read more >
NumPy 1.21.0 Release Notes
A deprecation warning will now be issued whenever getting np.typeDict . ... will give a FutureWarning that it will return an object array...
Read more >
pandas.DataFrame.mean() Examples
Provides a way to calculate mean on column axis. ... import pandas as pd import numpy as np technologies = ({ 'Courses':["Spark",np.nan ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found