-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
There was a problem hiding this 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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
'?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you annotate this?
There was a problem hiding this comment.
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
There was a problem hiding this 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): |
There was a problem hiding this comment.
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): | |||
""" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
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): |
There was a problem hiding this comment.
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
ok to merge, 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 |
thanks |
No description provided.