org.sonar.l10n.py.rules.python.S6730.html Maven / Gradle / Ivy
This rule raises an issue when a deprecated Numpy alias of a built-in type is used.
Why is this an issue?
In NumPy, some built-in types such as int
have aliases in the form of numpy.int
. However, these aliases have been
deprecated and should not be used anymore.
The following deprecated aliases should be replaced with their built-in alternatives:
Deprecated name
Equivalent built-in type
numpy.bool
bool
numpy.int
int
numpy.float
float
numpy.complex
complex
numpy.object
object
numpy.str
str
numpy.long
int
numpy.unicode
str
How to fix it
To fix this issue, make sure to replace deprecated NumPy type aliases with their corresponding built-in types.
Code examples
Noncompliant code example
import numpy as np
def foo():
x = np.int(42) # Noncompliant: deprecated type alias
Compliant solution
import numpy as np
def foo():
x = 42 # Compliant
Resources
Documentation
- NumPy Documentation - Data types
- NumPy Documentation - Deprecation of aliases of builtin types
© 2015 - 2024 Weber Informatics LLC | Privacy Policy