-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: MultiIndex.get_level_values() replaces NA by another value (#5074) #5090
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
Yes, your original answer is simplest (especially because it lets numpy handle all the casting) - it's a nice combination of clever and clear compared to what I was thinking. :) There's a pathological case where this would be far less efficient (MI initialized with many many labels, then sliced to only have a subset) because the append creates a copy, but I think your solution is better because it's less error-prone. Thanks for taking the time to work through this example! Please make sure you're testing this with labels that are string, date-like, integer and heterogeneous, as well as levels > 0. @jreback should this fill with |
yep date like should be NaT NaT is prob not missing considered missing because it's just using a view of i8 so it is preserved - so it 'works' correctly |
The problem is that, with the append method, it ends up forcing to dtype object if you append nan, so you need to check. Does that already exist? maybe in common there's something like |
Given the current behavoir of OTOH, it is worth testing |
On second thought, using a private method returning the correct NA value for an Index (as proposed before by @jreback) makes sense anyway. This decouples |
@jreback would take_1d in common be useful for this? |
yep
you can set fill_value from a method (which DatetimeIndex) can override, something like
in DatetimeIndex
|
I used |
@jtratner this looks fine to me...any more comments? |
@@ -394,6 +394,10 @@ def values(self): | |||
def get_values(self): | |||
return self.values | |||
|
|||
def _na_value(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.
why can't this just be a property? - much simpler.
#: the expected NA value to use with this index
_na_value = np.nan
etc.
@goyodiaz need a rebase |
@jtratner go ahead and merge |
BUG: MultiIndex.get_level_values() replaces NA by another value (#5074)
closes #5074
Do you really prefer using a mask? It seems to have a lower memory footprint but it requires some tricks for corner cases.