-
Notifications
You must be signed in to change notification settings - Fork 19
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
Gp/feat/aman arbitrary path #1057
base: master
Are you sure you want to change the base?
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.
Looks good -- a couple of requests though:
get
and__contains__
have not been changed. I think we should support the same treatment for keys provided there (but this is probably debatable).- The tests don't test very much right now... please expand.
- Mention this behavior in the docs (see axisman.rst, add a few lines after paragraph of "Note the boresight entry is marked with")
Thanks!
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 mattew covered everything I had in mind.
I think the answer to this is "not enough that we care" or "not enough to measure" but is there any noticeable slowdown from accessing children in this way?
Expanding the test case so show that the values that we get and set are correct I think is important.
Get is a combination of
Yes, this is measurable but how many levels down do you want to go? |
I think most people will never go beyond triple nested so if that slowdown is in the noise then I think we are good. If it somehow matters this seems like a case where we could cache the mapping from the full path to where they point to alleviate things (but I really dont think it will end up being an issue). |
Having changed It is nice to be able to check if |
Is this what you mean? It is in the commit that addresses the comments. I'm trying to get them all in a single push. |
Yes, that's what I mean. Thanks. |
I am not sure if the test makes sense in terms of operations. Let me know if I need to update it in a way that reflects the correct usage of the AxisManager class. |
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.
Thanks.
I think what's missing in the test is just a simple data field, such as a shape=(samps,) array, in child or child2. Check that accessing, and setting, that field using 'child.child2.target' works properly.
I updated the tests and added a I also timed them, using timeit and 1000 iterations and these are the results:
I consider these to be the same time. |
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 to me, I like the test a lot.
I have one minor issue with the docs and one potential feature to add but overall I think this is good to go.
) | ||
child2.wrap("tod", np.zeros((2,1000))) | ||
aman.wrap("child", child) | ||
aman["child"].wrap("child2", child2) |
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.
@mhasself do we want support in wrap
for these paths as well? ie aman.wrap('child.child2', ...)
?
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 am ok with that but let's leave it out for now.
@mhasself can you take another look? |
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.
Thanks -- a few more comments.
@@ -3,6 +3,7 @@ | |||
import os | |||
import shutil | |||
|
|||
from networkx import selfloop_edges |
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.
Unused import?
@@ -298,6 +299,56 @@ def test_300_restrict(self): | |||
self.assertNotEqual(aman.a1[0, 0, 0, 1], 0.) | |||
|
|||
# wrap of AxisManager, merge. | |||
def test_get_set(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.
The naming convention here is test_NNN_description. I propose you call this test_190_get_set
and move it upwards, before the # Multi-dimensional restrictions.
section.
) | ||
child2.wrap("tod", np.zeros((2,1000))) | ||
aman.wrap("child", child) | ||
aman["child"].wrap("child2", child2) |
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 am ok with that but let's leave it out for now.
if isinstance(val, AxisManager) and isinstance(tmp_item, AxisManager): | ||
raise ValueError("Cannot assign AxisManager to AxisManager. Please use wrap method.") | ||
|
||
tmp_item.__setattr__(val_key, val) |
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 a slight regression -- consider:
a = AxisManager()
a.x = 1
a['y'] = 1
The previous behavior was that a.x = 1
would work, but a['y'] = 1
would raise a KeyError. Please restore that behavior.
|
||
self.assertIn("child.dets", aman) | ||
self.assertIn("child.dets2", aman) # I am not sure why this is true | ||
self.assertNotIn("child.child2.someentry", aman) |
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.
add test
self.assertNotIn("child.child2.someentry.someotherentry", aman)
@@ -144,6 +144,26 @@ The output of the ``wrap`` cal should be:: | |||
Note the boresight entry is marked with a ``*``, indicating that it's | |||
an AxisManager rather than a numpy array. | |||
|
|||
Data access under an AxisManager is done based on field names. For example: |
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 your example, you construct a new aman. But in the flow of this documentation, an AxisManager already exists, which has been built up demonstrating the features and usage. The existing one has enough stuff to demonstrate all the features you need to demonstrate (e.g. dset.boresight.az
vs. dset['boresight.az']
). So please use that! (And that should flow into the "To slice this object..." section, which again refers to the dset
variable.)
Also this line for some reason renders in bold, in the docs... maybe add a blank line after? Not sure how you got away without a double ::
...
This PR updates AxisManager
__getitem__
and__setitem__
based on the slack discussion.__setitem__
raises an ValueError when the value is not another AxisManager and uses wrap to add it to the main object. I selected wrap because it seemed more complete compared to merge.