Skip to content

python/float-around-number

Rule float-around-number
Pack Python
Severity warning
Fix none, edit by hand
Library versions every version

A number from a float64 array or a Series is a float already, and so is arithmetic on it. Drop the float(), and keep it only for text, an int, or a float32.

def cheapest(prices: np.ndarray, sold: np.ndarray) -> tuple[float, float]:
best = prices.argmin()
return float(prices[best]), float(sold[best] * 2)
return prices[best], sold[best] * 2

The rule reports float() around a subscript, a name, an attribute or arithmetic, in a file that imports numpy or pandas. It leaves alone a string and a value whose name points at text, such as a regex group, a split, a header or the environment.

xpd has no automatic fix, so make the change by hand.

A number taken from a float64 array or a Series is an np.float64, and so is arithmetic on it. On NumPy 2.5.5 and pandas 3.1.1, isinstance(value, float) was True for a[0], a[0] * 3, s.iloc[0], s.sum() and s.max(). Keep the call in three cases: the value is text, the value is an int that has to become a float, or the array holds float32. The file does not show which case a call is, so the rule has no fix.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

A number from a float64 array or a Series is a float already, and so is arithmetic on it. Drop this float(), and keep it only for text, for an int that has to become a float, or for a float32.

Browse the other rules of the Python pack.