Skip to content
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

Adding numpy as requirement for installation. (was adding numpy as requirement) #672

Closed
c-w-feldmann opened this issue May 2, 2023 · 12 comments · Fixed by #696
Closed

Comments

@c-w-feldmann
Copy link

Describe the bug
Hey,
we have a environment where only linters are installed. After running mypy . we install all missing subs with mypy --install-types --non-interactive.
After running mypy --ignore-missing-imports --disallow-any-generics --disallow-untyped-defs --no-implicit-optional --disallow-incomplete-defs . we geht an error for accessing a series:

dummy = test_df["dummy"].tolist()

Raises:
bug_minimal_example.py:5: error: "Series[Any]" not callable [operator]
Found 1 error in 1 file (checked 1 source file)

Error vanishes after numpy or pandas is installed.
To Reproduce

import pandas as pd

test_df = pd.DataFrame()
test_df["dummy"] = [1, 2, 3, 4, 5]
dummy = test_df["dummy"].tolist()
print(dummy)

bug_minimal_example.py:5: error: "Series[Any]" not callable [operator]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

  • OS: Ubuntu [WSL]
  • OS Version: 22.04.2 LTS
  • python version: 3.8
  • version of type checker: mypy 1.2.0
  • version of installed pandas-stubs: 2.0.1.230501

Additional context
Suggested fix:
Adding pandas to requirements

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 2, 2023

It's not pandas, it is numpy. You have to have numpy installed because we depend on the typing provided by numpy. I removed pandas from my environment, and your code passed. When I removed numpy, I then got the same error message.

I think we will need to add numpy as a requirement.

@twoertwein Your thoughts?

@twoertwein
Copy link
Member

I'm very hesitant to add (large) runtime dependencies to pandas-stubs. I believe we got the opposite issues when we had pandas/typing-extensions as a dependency. I think typeshed stubs do not(?) have dependencies.

Does this error also happen with pyright?

@JelleZijlstra
Copy link

I think typeshed stubs do not(?) have dependencies.

They do. If a typeshed stub package used numpy in its stubs, we'd add numpy as a dependency.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 2, 2023

Does this error also happen with pyright?

Yes, same as with mypy. So pyright isn't seeing that the numpy referenced by an installed version of pandas-stubs is missing.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 2, 2023

Does this error also happen with pyright?

Yes, same as with mypy. So pyright isn't seeing that the numpy referenced by an installed version of pandas-stubs is missing.

Although if you don't have pandas installed, then you do get a message from pyright about it not being resolved from source. Whereas mypy gives no such warning.

@twoertwein
Copy link
Member

I think typeshed stubs do not(?) have dependencies.

They do. If a typeshed stub package used numpy in its stubs, we'd add numpy as a dependency.

I guess we should then make numpy a dependency (and theoretically all the other non-pandas libraries)

@gandhis1
Copy link
Contributor

gandhis1 commented May 2, 2023

Asking an obvious question here, but is there any context in which pandas-stubs would be useful and one did not have pandas installed? Cause if not, then you have pandas installed, and you thereby have numpy installed.

I don't know what the convention is, but I just pulled up django-stubs for instance, and they appear to have django itself as a dependency, So extrapolating from a sample size of one....maybe the proper thing to do is in fact have the actual package as a dependency of the stub package?

@Dr-Irv Dr-Irv changed the title Adding pandas as requirement for installation. Adding ~~pandas~~ numpy as requirement for installation. May 2, 2023
@Dr-Irv Dr-Irv changed the title Adding ~~pandas~~ numpy as requirement for installation. Adding numpy as requirement for installation. (was adding numpy as requirement) May 2, 2023
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 2, 2023

Asking an obvious question here, but is there any context in which pandas-stubs would be useful and one did not have pandas installed? Cause if not, then you have pandas installed, and you thereby have numpy installed.

Context is in the original part of the issue. Someone wanted to just do type checking using the stubs without installing any of the packages.

@c-w-feldmann
Copy link
Author

Context is in the original part of the issue. Someone wanted to just do type checking using the stubs without installing any of the packages.

If you mean me, at least from our site it would be totally fine to install numpy (or pandas). I just wanted to explain how we had an environment which has pandas-stubs but not pandas itself installed.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 18, 2023

FYI, mypy people said the option --no-install-site-packages is a way to detect that packages that are being checked are not installed.

@twoertwein
Copy link
Member

Should we run mypy with --no-silence-site-packages on the CI?

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 18, 2023

Should we run mypy with --no-silence-site-packages on the CI?

It would then pick up that things like matplotlib has no typing, so I don't think we should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants