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

Associated arbitrary grid edge unit registry with dataset unit registry for issue #2087 #2119

Merged
merged 4 commits into from Dec 10, 2018
Merged

Conversation

jcoughlin11
Copy link
Contributor

@jcoughlin11 jcoughlin11 commented Dec 7, 2018

PR Summary

This PR associates the unit registry of the YTArray edge in _sanitize_edge with that of the dataset that the arbitrary grid is being constructed for. This is needed because if the user passes non-dataset units for the edge, i.e.

ag = ds.arbitrary_grid(left_edge = [0,0,0] * yt.units.kpc,
    right_edge = [1,1,1] * yt.units.kpc,
    dims = [32,32,32])

then when yt attempts to get the data, there was a UnitParseError. This fixes that error.

Issue #2087

PR Checklist

  • Code passes flake8 checker
  • New features are documented, with docstrings and narrative docs
  • Adds a test for any bugs fixed. Adds tests for new features.

Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

Nice!

My only comment is that there's a lot of repeated code in the tests. I think you could rewrite it as a for loop like this:

for le, re, le_answer, re_answer in zip(les, res, le_answers, re_answers):
    ag = ds.arbitrary_grid(left_edge=le, right_edge=re, dims=dims)
    assert np.array_equal(ag.left_edge, le_answer)
    assert np.array_equal(ag.right_edge, re_answer)
    assert ag.left_edge.units.registry == ds.unit_registry
    assert ag.right_edge.units.registry == ds.unit_registry
    ag['density']

Where les, res, le_answers, and re_answers are lists or arrays of the all of the inputs and answers you're expecting.

Writing it like this is more maintainable since it makes it easier for future editors to change one section of the test without also forgetting to update the other sections.

@ngoldbaum ngoldbaum merged commit 9eb22e2 into yt-project:master Dec 10, 2018
@jcoughlin11 jcoughlin11 deleted the issue-2087 branch December 10, 2018 17:42
ngoldbaum pushed a commit to ngoldbaum/yt that referenced this pull request Feb 22, 2019
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.

None yet

2 participants