pandas2 icon indicating copy to clipboard operation
pandas2 copied to clipboard

Type annotations

Open shoyer opened this issue 8 years ago • 9 comments

Given that we seem to be on board with only supporting Python 3 (#5) in pandas 2.0, let's take full advantage of that and require type annotations for all internal pandas code. Users, of course, are free to ignore them as they please, but we can run mypy or pytype as part of our continguous integration tests to check for bugs.

Why?

  1. Static typing catches loads of bugs, both for us and our users
  2. Documenting types in code is far more reliable than in doc-strings
  3. Such a constraint would provide strong pressure for writing functions with sane type signatures

Quite simply, this is just good software engineering.

shoyer avatar Sep 08 '16 01:09 shoyer

+1.

My biggest annoyance has been with the repetition between types in the annotations and types in the docstrings. Presumably we could write a little decorator that pulls type-info from the function signature and puts them in the docstring (via a Jinja2 template or something).

https://www.python.org/dev/peps/pep-0526/ (new syntax for variable annotations) was recently accepted for 3.6. Have we talked at all about what version of python3 we're targeting? Separate issue?

TomAugspurger avatar Sep 08 '16 13:09 TomAugspurger

I'm currently working with pycharm and autogenerated docstrings and function signatures (matplotlibs new data arguments) are a big pain as IDEs like pycharm gets these info without starting an interpreter :-(

jankatins avatar Sep 08 '16 18:09 jankatins

I'm definitely in favor of this. have there been any decisions made about what python versions will be supported?

@janschulz we might look into building a complimentary stub package for pycharm for matplotlib for the time being. auto-generated code is a huge pain.

brmc avatar Mar 12 '17 13:03 brmc

@brmc we would certainly take a type stub type of file (in the current pandas repo actually). This is really a user facing file. Ideally would support both py2 & py3 (obviously py2 is quite useful for folks migrating). If you are interested please submit a PR.

jreback avatar Mar 12 '17 15:03 jreback

For pandas 2, I think the plan is Python 3 only (see #5 ).

shoyer avatar Mar 12 '17 15:03 shoyer

type annotations would be quite useful for py2; these are also about the user api which is not likely to change much

pandas2 is still a while off

jreback avatar Mar 12 '17 16:03 jreback

@jreback to be clear, I am all for starting early on annotations! This issue is on the pandas 2 tracker, though.

shoyer avatar Mar 12 '17 16:03 shoyer

@brmc so in reality this should be discussed on https://github.com/pandas-dev/pandas/issues/14468

jreback avatar Mar 12 '17 16:03 jreback

continuing conversation on pandas-dev/pandas#14468

brmc avatar Mar 12 '17 18:03 brmc