pylance-release
pylance-release copied to clipboard
Operator "-" not supported for types "DataFrame" and "Series[Dtype@mean]
- Language Server version: v2021.11.2
- OS and version: macOS 10.15.7
- Python version: 3.8.2
Actual behaviour
import numpy as np
import pandas as pd
columns = ['A']
df = pd.DataFrame(np.random.randint(0, 100, size=(100, 1)), columns=columns)
# Normalization
df = (df - df.mean()) / df.std()
Operator "-" not supported for types "DataFrame" and "Series[Dtype@mean]"
Operator "-" not supported for types "DataFrame" and "Series[Dtype@mean]"
PylancereportGeneralTypeIssues
# Denormalization
epsilon = 1e-100
coefficients = pd.DataFrame()
coefficients['mean'] = df.loc[:, columns].mean()
coefficients['std'] = df.loc[:, columns].std() + epsilon
coefficients = coefficients.T
column = 'A'
std = coefficients.loc['std', column]
mean = coefficients.loc['mean', column]
df[column] = X[column] * std + mean
Operator "*" not supported for types "Series[Dtype@__getitem__]" and "Scalar"
PylancereportGeneralTypeIssues
Is this related to such an effect?
import numpy as np
def f(x: np.ndarray, y: np.ndarray):
return x - y # Operator "-" not supported for types "ndarray[Unknown, Unknown]" and "ndarray[Unknown, Unknown]" Pylance(reportGeneralTypeIssues)
The error is with "python.analysis.typeCheckingMode": "basic" and it goes away when switching to "off". This seems to have appeared since I've updated to a recent NumPy version (1.22.3), so it might also be related to the new typing specifications in NumPy. Other info:
- OS: Ubuntu 20.04 and Windows 10
- Python: Python 3.8.10 (Ubuntu) and Python 3.10.4 (Windows)
- Pylance: v2022.4.3 (Ubuntu) and another recent version on Windows (currently not accessible)
These should be fixed in the latest numpy typestubs. See #3475