Skip to content

Add type hinting to public-facing API in pandas/core/generic.py #26792 #29543

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

Closed
wants to merge 3 commits into from

Conversation

tobyjamez
Copy link

@@ -728,7 +730,7 @@ def _set_axis(self, axis, labels):
self._data.set_axis(axis, labels)
self._clear_item_cache()

def transpose(self, *args, **kwargs):
def transpose(self, *args, **kwargs) -> "NDFrame":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we start adding type hints to public functions (maybe we already have other places where we do this, but just noticing it here): we should think about what to do with "NDFrame".
This is not a "public term", and IMO no user should see this.

Should it be replaced with a union of Series and Frame?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonjayhawkins should this by pd._typing._T?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonjayhawkins should this by pd._typing._T?

pd._typing._T is for unbound types (normally objects in a generic container). we should use TypeVar("FrameOrSeries", bound="NDFrame") in core.generic

this is currently pd._typing.FrameOrSeries. some potentially relevant discussion in #29480

This is not a "public term", and IMO no user should see this.

that's a reasonable agrument and perhaps also relevant to #29480

@jbrockmendel
Copy link
Member

you need to run isort pandas/core/generic.py

@@ -553,7 +555,7 @@ def _stat_axis(self):
return getattr(self, self._stat_axis_name)

@property
def shape(self):
def shape(self) -> Tuple[int]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be Tuple[int, ...]?

@@ -772,7 +774,7 @@ def transpose(self, *args, **kwargs):
nv.validate_transpose(tuple(), kwargs)
return self._constructor(new_values, **new_axes).__finalize__(self)

def swapaxes(self, axis1, axis2, copy=True):
def swapaxes(self, axis1: int, axis2: int, copy=True) -> "NDFrame":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int here isnt quite right. I think its pandas._typing.Axis

@jbrockmendel jbrockmendel added the Typing type annotations, mypy/pyright type checking label Dec 3, 2019
@jreback
Copy link
Contributor

jreback commented Jan 1, 2020

closing as stale, some of this has been done, welcome for PRs to continue

@jreback jreback closed this Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants