Skip to content

TYP: mostly core.arrays, some core.indexes #40545

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

Merged
merged 11 commits into from
Apr 2, 2021

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

@jbrockmendel jbrockmendel reopened this Mar 20, 2021
@jbrockmendel jbrockmendel added the Typing type annotations, mypy/pyright type checking label Mar 21, 2021
@jbrockmendel jbrockmendel changed the title TYP: annotate all the things TYP: mostly core.arrays, some core.indexes Mar 22, 2021
@jreback jreback added this to the 1.3 milestone Mar 23, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

Axis typing

@@ -952,7 +952,7 @@ def freqstr(self):
return self.freq.freqstr

@property # NB: override with cache_readonly in immutable subclasses
def inferred_freq(self):
def inferred_freq(self) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we have a Freq typing?

Copy link
Member Author

Choose a reason for hiding this comment

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

we do, but this is more specific

@@ -205,12 +205,12 @@ def _values_for_factorize(self) -> Tuple[np.ndarray, int]:
# ------------------------------------------------------------------------
# Reductions

def any(self, *, axis=None, out=None, keepdims=False, skipna=True):
def any(self, *, axis=None, out=None, keepdims: bool = False, skipna: bool = True):
Copy link
Contributor

Choose a reason for hiding this comment

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

can type Axis

Copy link
Member Author

Choose a reason for hiding this comment

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

updated


def take(
self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs
self, indices, axis: int = 0, allow_fill: bool = True, fill_value=None, **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

Axis

Copy link
Member Author

Choose a reason for hiding this comment

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

Axis includes str that is only for Series/DataFrame

Copy link
Member Author

Choose a reason for hiding this comment

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

these are correct as-is, but if for some reason theyre a deal-breaker ill revert to push this through

Copy link
Contributor

Choose a reason for hiding this comment

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

no its fine, i get that these have to be ints

""" return the size of my table in bytes """
overhead = 4 * sizeof(uint32_t) + 3 * sizeof(uint32_t*)
for_flags = max(1, self.table.n_buckets >> 5) * sizeof(uint32_t)
for_pairs = self.table.n_buckets * (sizeof({{dtype}}_t) + # keys
sizeof(Py_ssize_t)) # vals
return overhead + for_flags + for_pairs

def get_state(self):
def get_state(self) -> dict[str, int]:
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be consistent about this pattern, IIRC we use Dict[str, int] ? cc @simonjayhawkins ok either way, we should have a rule and convert

Copy link
Member

Choose a reason for hiding this comment

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

IIUC there was no objection to using the new syntax, just not ready to convert all existing annotations yet. I recall a discussion about this and I _think_the outcome was that we would wait till closer to 1.3 to use pyupgrade to reduce the potential conflicts with backports but I can't find the relevant discussion. @MarcoGorelli

Copy link
Member

Choose a reason for hiding this comment

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

It was #39930

Removing --keep-runtime-typing will upgrade to newer syntax in files with from __future__ import annotations

Copy link
Member

Choose a reason for hiding this comment

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

ahh yes. it was because mypy in 1.2.x is on an older version. #39538 (review)

nbd. can fixup the backports if necessary to use the older syntax. so imo can do whenever.

keepdims=False,
skipna=True,
keepdims: bool = False,
skipna: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

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

can return type all of theses i guess as Union[Scalar, ndarray] .....


def take(
self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs
self, indices, axis: int = 0, allow_fill: bool = True, fill_value=None, **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

no its fine, i get that these have to be ints

@jreback jreback merged commit 105f7fa into pandas-dev:master Apr 2, 2021
@jreback
Copy link
Contributor

jreback commented Apr 2, 2021

cool one comment above for potential followon

@jbrockmendel jbrockmendel deleted the typ-indexes branch April 2, 2021 02:21
vladu pushed a commit to vladu/pandas that referenced this pull request Apr 5, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
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.

4 participants