Skip to content
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

Add ability to deal with masked arrays to find_intersections #372

Merged
merged 2 commits into from
Mar 30, 2017

Conversation

jrleeman
Copy link
Contributor

Adds a helper function and streamlines its use in find_intersections. It will need some tests of course, but let's start with talking about how we want to modify the inner workings.

Copy link
Member

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

A little ugly, but could go in for now. Question: is only looking in one direction (i.e. you keep adding 1) enough? Do you ever need to look backwards?

@@ -157,3 +158,35 @@ def interpolate_nans(x, y, kind='linear'):
else:
raise ValueError('Unknown option for kind: {0}'.format(str(kind)))
return y[x_sort_args]


@exporter.export
Copy link
Member

Choose a reason for hiding this comment

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

Given that this could go away in the future, I'm not ready to export this. I'd even consider naming with a leading underscore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair - Can do. Re above - I don't think we ever need to look back. nearest_intersection_idx shouldn't ever return a masked point.

@jrleeman jrleeman force-pushed the LFC_Masked_Arrays branch 2 times, most recently from 587b78c to aab6a6d Compare March 28, 2017 21:41
@jrleeman
Copy link
Contributor Author

Looks good to go unless you see anything else @dopplershift

Copy link
Member

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Sorry, I thought of a few things. 😀

-------
Index of next non-masked element and next non-masked element
"""
if hasattr(a, 'mask'):
Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking here (LBYL-Look Before You Leap), use EAFP (Easier to Ask Forgiveness than Permission):

try:
   ...
except AttributeError:
   return idx, a[idx]

hasattr() ends up calling getattr() anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So is that an efficiency gain or mainly style thing?

Copy link
Member

Choose a reason for hiding this comment

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

Ever so slight gain in efficiency has convinced me of choosing EAFP over LBYL; code clarity, of course, dominates all of that, but that's not the case here.

"""
if hasattr(a, 'mask'):
next_idx = idx
while ma.is_masked(a[next_idx]):
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this loop, how about:

next_idx = idx + a[idx:].mask.argmin()

@jrleeman
Copy link
Contributor Author

Looks like we have to catch all three errors for the entire build matrix to pass. If that sounds fine, I'll fixup the commits.

@dopplershift
Copy link
Member

Sounds good, rebase and we should be good to go.

@jrleeman
Copy link
Contributor Author

Done! I really hope we can kill this soon - it's not pretty, but sadly necessary.

@dopplershift dopplershift modified the milestone: 0.5.0 Mar 30, 2017
@jrleeman
Copy link
Contributor Author

rebasing now so it can be next in line for merge

@jrleeman
Copy link
Contributor Author

Ready to go :shipit:

@dopplershift dopplershift merged commit c566269 into Unidata:master Mar 30, 2017
@jrleeman jrleeman deleted the LFC_Masked_Arrays branch April 4, 2017 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants