-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect 'unsubscriptable-object' reported #3637
Comments
Same problem with this:
|
Have a similar problem with type hints. This LoC EnvVarTypes = Union[str, int, float, bool, None] gives This LoC def validate(self, line: str, _: GitCommit) -> List[Optional[RuleViolation]]: gives BUT those errors only occur in with $ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.9.0 (default, Oct 6 2020, 02:47:17)
[GCC 7.5.0] and not with $ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Oct 6 2020, 03:22:36)
[GCC 7.5.0] |
This also breaks PEP 560 and PEP 585. See this comment at the related issue #3882. |
@beauxq thanks for your comment. It seems your issue is not linked to the original one. Morevoer it should have been fixed through pylint-dev/astroid#831. |
@Cielquan thanks for your report. However your issue is not linked to the original one but it is due to the fact |
To any people thinking adding a comment here, please do only if your problem seems to be linked to |
Another case that breaks our code checking CI/CD: """Pylint unsubscriptable-object example"""
import pandas as pd
result = pd.DataFrame()
cols = ['a', 'b', 'c', 'd']
CSVDATA = 'data.csv'
df = pd.read_csv(CSVDATA)
df['d'] = [CSVDATA.split('.', maxsplit=1)[0]] * df.shape[0]
result = pd.concat([result, df[cols]], axis=0)
print(result) Pylint reports:
|
@MiltiadisKoutsokeras got any solution to remove this error ? I am facing the same but on initializing i.e on |
For those trying to fix this issue, the case I reported in #6942 may be useful: import pandas as pd # type: ignore
df = pd.read_csv("data.csv")
df_a = df.drop(columns=["a"])
df_b = df["b"] gives an unsubscriptable-object error message, but swapping the lines doesn't: import pandas as pd # type: ignore
df = pd.read_csv("data.csv")
df_b = df["b"]
df_a = df.drop(columns=["a"]) Hope this helps! |
I ran into this issue myself, and after looking over some examples here and in related/duplicated tickets, I have a hunch that the cause is that methods like I'd argue this is still something to fix in Pylint, because these Pandas methods ONLY seem to return None when |
Note that now the original example (and similar cases) now give import statsmodels.api as sm
data = sm.datasets.longley.load_pandas().data
properties = ['GNP', 'POP']
specificData = data[properties] ************* Module yetanotherbug
yetanotherbug.py:4:0: C0103: Constant name "data" doesn't conform to UPPER_CASE naming style (invalid-name)
yetanotherbug.py:7:15: E1136: Value 'data' is unsubscriptable (unsubscriptable-object) Also, juliangilbey's example is now fixed with the latest versions of pylint and pandas. |
I cannot reproduce this issue with the above snippets. However, the following snippet reproduces the issue: """Pylint unsubscriptable-object example"""
import random
import pandas as pd
data = []
for n in range(random.randint(0, 10)):
data.append({"number": n**2})
df = pd.DataFrame(data) if len(data) > 0 else None
if df is None:
raise ValueError("DataFrame is empty")
print(df["number"].sum())
df = pd.DataFrame(df) # This line clears the error (and is my workaround for now)
print(df["number"].sum())
Thanks for taking the time to look into this. |
Steps to reproduce
Running Pylint on the following code will produce the error on the last line.
Current behavior
Running Pylint gives
Expected behavior
No errors/warnings should be produced.
pylint --version output
pylint 2.5.2
astroid 2.4.1
Python 3.7.7 (default, Apr 14 2020, 11:51:19)
[Clang 11.0.0 (clang-1100.0.33.12)]
The text was updated successfully, but these errors were encountered: