Rules for Clean Code with Numpy and Python Computations

Hello Data Scientists & Pythonistas,

We are excited to announce the support of a first set of computational and Numpy library rules to help you write Clean Code.

These are the new rules:

  • S1244 - Floating point numbers should not be tested for equality
  • S6709 - Results that depend on random number generation should be reproducible
  • S6711 - numpy.random.Generator should be preferred to numpy.random.RandomState
  • S6714 - Passing a list to np.array should be preferred over passing a generator
  • S6725 - Equality checks should not be made against “numpy.nan”
  • S6727 - The abs_tol parameter should be provided when using math.isclose to compare values to 0
  • S6729 - np.nonzero should be preferred over np.where when only the condition parameter is set
  • S6730 - Deprecated NumPy aliases of built-in types should not be used

These rules will be available in SonarCloud shortly and will be available in SonarQube 10.3. They will also be available in the next version of SonarLint with quick fixes for S1244, S6725, and S6729 in supported IDEs.

As always, we welcome your feedback and questions on these rules. Remember that you can vote for and see what’s coming up for Python in SonarLint, SonarQube and SonarCloud. Enjoy!