Skip to content

CLEAN: Reconcile types in pandas._typing.py and pandas-stubs._typing.pyi #128

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

Open
Dr-Irv opened this issue Jul 10, 2022 · 8 comments
Open

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 10, 2022

There are some inconsistencies in types in pandas._typing.py and pandas-stubs._typing.pyi . These should be reconciled.

In addition, types that are only in the stubs should probably be private with a leading underscore _

@bashtage
Copy link
Contributor

Are there any tools that will help keep stubs in sync with pandas? When I went through io/stata.py there were a lot of changes since these were originally collatted.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jul 20, 2022

Are there any tools that will help keep stubs in sync with pandas? When I went through io/stata.py there were a lot of changes since these were originally collatted.

Not that I'm aware of. Maybe stubtest could help

@twoertwein
Copy link
Member

Might not make sense to fix all of them (some exist on main but not in 1.4.x) but it gives a quick overview what could be changed poe stubtest | grep "pandas\._typing"

pandas._typing.AggFuncTypeDict is not a type
pandas._typing.Axes is not a Union
pandas._typing.AxisType is not present at runtime
pandas._typing.BaseBuffer.init is inconsistent, stub does not have *args argument "args"
pandas._typing.Buffer is not present at runtime
pandas._typing.CompressionDict is not a type
pandas._typing.ConvertersArg is not present at runtime
pandas._typing.DateTimeErrorChoices is not present at runtime
pandas._typing.DatetimeLikeScalar is not a TypeVar
pandas._typing.DtypeNp is not present at runtime
pandas._typing.FileOrBuffer is not present at runtime
pandas._typing.FilePathOrBuffer is not present at runtime
pandas._typing.FilePathOrBytesBuffer is not present at runtime
pandas._typing.FrameOrSeries is not present at runtime
pandas._typing.FrameOrSeriesUnion is not present at runtime
pandas._typing.FuncType is not a recognised type alias
pandas._typing.Function is not present at runtime
pandas._typing.GroupByObject is not present at runtime
pandas._typing.GroupByObjectNonScalar is not present at runtime
pandas._typing.HashableT is not present at runtime
pandas._typing.IgnoreRaise is not present at runtime
pandas._typing.IndexType is not present at runtime
pandas._typing.IndexingInt is not present at runtime
pandas._typing.IntervalClosedType is not present at runtime
pandas._typing.KeysArgType is not present at runtime
pandas._typing.Label is not present at runtime
pandas._typing.ListLike is not present at runtime
pandas._typing.MaskType is not present at runtime
pandas._typing.ParseDatesArg is not present at runtime
pandas._typing.ReadBuffer.init is inconsistent, stub does not have *args argument "args"
pandas._typing.S1 is not present at runtime
pandas._typing.ScalarT is not present at runtime
pandas._typing.SeriesAxisType is not present at runtime
pandas._typing.StrLike is not present at runtime
pandas._typing.T1 is not present at runtime
pandas._typing.T2 is not present at runtime
pandas._typing.WriteBuffer.init is inconsistent, stub does not have *args argument "args"
pandas._typing.XMLParsers is not a Union
pandas._typing.all is not present at runtime
pandas._typing.np_ndarray_anyint is not present at runtime
pandas._typing.np_ndarray_bool is not present at runtime
pandas._typing.np_ndarray_int is not present at runtime
pandas._typing.np_ndarray_int16 is not present at runtime
pandas._typing.np_ndarray_int32 is not present at runtime
pandas._typing.np_ndarray_int64 is not present at runtime
pandas._typing.np_ndarray_int8 is not present at runtime
pandas._typing.np_ndarray_str is not present at runtime
pandas._typing.np_ndarray_uint is not present at runtime
pandas._typing.np_ndarray_uint16 is not present at runtime
pandas._typing.np_ndarray_uint32 is not present at runtime
pandas._typing.np_ndarray_uint64 is not present at runtime
pandas._typing.np_ndarray_uint8 is not present at runtime
pandas._typing.num is not present at runtime
pandas._typing.type_t is not a type

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Aug 5, 2022

Can this tell us which ones are in pandas._typing.py, but not pandas._typing.pyi ?

Also would be best if we could use what is in main from pandas just to keep things moving forward.

@twoertwein
Copy link
Member

Can this tell us which ones are in pandas._typing.py, but not pandas._typing.pyi ?

I think so, would probably need to remove --ignore-missing-stub from the stubtest call.

Also would be best if we could use what is in main from pandas just to keep things moving forward.

stubtest will use whichever version of pandas that is installed. Currently, that is 1.4.x. I think pandas has nightly builds, we could install that in pyproject.toml instead of 1.4.x: but then we might get some "troubles" with pytests, more deprecation warnings (before 1.5) and breaking changes (after 1.5 is released).

@twoertwein
Copy link
Member

Can this tell us which ones are in pandas._typing.py, but not pandas._typing.pyi ?

I wrote some quick&ugly ast parsing code to check when pandas-stubs has annotations but pandas has none (I have been using it for pandas-dev/pandas#47827 and similar PRs). Could extend that, but stubtest without --ignore-missing-stub would be a better choice.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Aug 5, 2022

stubtest will use whichever version of pandas that is installed. Currently, that is 1.4.x. I think pandas has nightly builds, we could install that in pyproject.toml instead of 1.4.x: but then we might get some "troubles" with pytests, more deprecation warnings (before 1.5) and breaking changes (after 1.5 is released).

Maybe you could just figure out a way to run stubtest (but not mypy, pytest, etc.) against the current version in pandas/main so we can start reconciling the types. There is good typing work in pandas that we can pull over to the stubs without making the stubs incorrect for 1.4.x

@twoertwein
Copy link
Member

Could have a step ala "remove pandas 1.4x. and install pandas nightly" with an appropriate rollback.

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

No branches or pull requests

3 participants