Skip to content

CLN/REF: indexing typing, prune unreachable branches #27351

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 17 commits into from
Jul 12, 2019

Conversation

jbrockmendel
Copy link
Member

No description provided.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Some hopefully helpful comments. Generally annotating return types would be nice too

@@ -2889,11 +2889,11 @@ def _set_value(self, index, col, value, takeable=False):

_set_value.__doc__ = set_value.__doc__

def _ixs(self, i, axis=0):
def _ixs(self, i: int, axis: int = 0):
Copy link
Member

Choose a reason for hiding this comment

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

Since axis is a pretty common keyword can you put that as Axis in pandas._typing? We probably also want to add str as a type for it since it should accept "index" and "columns" as well

Copy link
Member

Choose a reason for hiding this comment

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

Also can we add the return type here? -> '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.

I'll take a look and see what we can determine about return types. For Axis/str/int, in all these cases, I've put int because these are private methods and only ever get ints.

if axis is None:
axis = self.axis or 0

def _get_label(self, label, axis: int):
Copy link
Member

Choose a reason for hiding this comment

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

Can label be Hashable?

@@ -656,6 +578,65 @@ def setter(item, v):
self.obj._data = self.obj._data.setitem(indexer=indexer, value=value)
self.obj._maybe_update_cacher(clear=True)

def _setitem_with_indexer_missing(self, indexer, value):
Copy link
Member

Choose a reason for hiding this comment

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

Can you annotate this?

Copy link
Member Author

Choose a reason for hiding this comment

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

itd just be Any for both of em. Is that materially better than leaving it blank? In general I prefer to leave it blank rather than put a too-loose type that I'm not sure about

@WillAyd WillAyd added Clean Typing type annotations, mypy/pyright type checking labels Jul 11, 2019
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.

looks good. some small changes. ping on green.

def _slice(self, obj, axis=None, kind=None):
if axis is None:
axis = self.axis
def _slice(self, obj, axis: int, kind=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

kind=Optional[str]

@@ -656,6 +578,65 @@ def setter(item, v):
self.obj._data = self.obj._data.setitem(indexer=indexer, value=value)
self.obj._maybe_update_cacher(clear=True)

def _setitem_with_indexer_missing(self, indexer, value):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a doc-string though

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather not. If I did, it would just say both parameters are object, which may be too loose. I'd rather leave it open for someone to reason about and add a more-correct version.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually I think spitting this into a ndim==1 and a ndim==2 functions would be helpful (future PR ok)

@jreback jreback added this to the 0.25.0 milestone Jul 12, 2019
@jreback
Copy link
Contributor

jreback commented Jul 12, 2019

still would like to move to a unified pandas/core/indexing/..... structure sooner rather than later

@@ -3495,7 +3495,7 @@ def __delitem__(self, key):
deleted = False

maybe_shortcut = False
if hasattr(self, "columns") and isinstance(self.columns, MultiIndex):
if self.ndim == 2 and isinstance(self.columns, MultiIndex):
Copy link
Contributor

Choose a reason for hiding this comment

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

in the future change to use ABCMultiIndex

@jreback
Copy link
Contributor

jreback commented Jul 12, 2019

ok to merge, though if you want to split the setting routine I think might be helpful here.

@jbrockmendel
Copy link
Member Author

though if you want to split the setting routine I think might be helpful here.

will do in next round. lots of balls (branches) in the air

@jreback
Copy link
Contributor

jreback commented Jul 12, 2019

though if you want to split the setting routine I think might be helpful here.

will do in next round. lots of balls (branches) in the air

k

@jreback jreback merged commit c633579 into pandas-dev:master Jul 12, 2019
@jreback
Copy link
Contributor

jreback commented Jul 12, 2019

thanks

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

Successfully merging this pull request may close these issues.

3 participants