-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Add Index.fillna #11343
ENH: Add Index.fillna #11343
Conversation
if len(index) == 0: | ||
pass | ||
elif isinstance(index, MultiIndex): | ||
pass |
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.
assert NotImplementedError here
Thanks, did the suggested changes. A test fails in |
163b6cc
to
c08ac92
Compare
Rebased, and now green. |
try: | ||
np.putmask(values, mask, value) | ||
return self._shallow_copy(values) | ||
except ValueError: |
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 think if this catches TypeError as well it can be much more generic
Thanks, simplified the logic based on the comments. |
return np.array([], dtype=np.int64) | ||
|
||
@cache_readonly | ||
def hasnans(self): |
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.
this is override core/base.py
, but do we use that anylonger? (I don't think Series
uses 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.
I haven't notice base.py
. Should remove it from base.py
because Series
can be changed inplace?
-------- | ||
numpy.ndarray.putmask | ||
""" | ||
try: |
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.
you don't need this any longer once you call _assert_can_do_op
in Index.putmask
687ce6a
to
bf1f842
Compare
6ea192b
to
b20820a
Compare
Thanks, updated based on the comments.
|
|
||
if isinstance(item, np.datetime64): | ||
# np.datetime64 doesn't have tz, once convert to Timestamp | ||
item = Timestamp(item) |
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.
hmm, this seems to be not necessary?
e.g. you are checking if its np.datetime64
below so it will never be the case?
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.
Ah, needs change. This is for current _has_same_tz
cannot get tz
from np.datetime64
.
- move the condition to
_has_same_tz
? ( convertnp.datetime64
toTimestamp
). - If we keep 1594th line, 1598th line can be
if isinstance(item, datetime):
Maybe option 1 looks better?
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.
yeh 1 is better, this might work
vzone = tslib.get_timezone(getattr(Timestamp(other), 'tzinfo', '__no_tz__'))
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 if you always wrap other then you can simply return Timestamp(other).tz
I think
(though may be overlooking something)
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 _has_same_tz
, other
can be DTI or list-likes. Thus added if
for np.datetime64
.
@sinhrks looks really good! just a minor comment / question |
Reabsed, and now green. |
lgtm merge when ready thanks! might want to add s short example in the Index docs (iirc where we go over Index set ops) |
Thanks. Added brief doc to |
Missing values | ||
~~~~~~~~~~~~~~ | ||
|
||
.. _indexing.missing: |
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 put this above the title?
@sinhrks Looks good! One more remark, doc-wise: I see there is a |
@sinhrks thanks! always gr8 PR's from you! |
I don't see an entry in |
Closes #10089.
value
can only accept scalar.MultiIndex.fillna
raisesNotImplementedError
becauseisnull
is not defined for MI.hasnans
and related properties to baseIndex
.