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

BUG: Add a case in p4p_plugin_component.py for Numpy integers. #1120

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

slactjohnson
Copy link
Contributor

Adds an additional case in the p4p_plugin_component module for Numpy integers.

Tested using an in-development GUI on the same PV described in #1119

Closes #1119

@nstelter-slac
Copy link
Collaborator

nstelter-slac commented Oct 22, 2024

looks good, thanks!

can we also add a test for passing in the np.int32, in this test-case probably: https://github.com/slaclab/pydm/blob/master/pydm/tests/data_plugins/test_p4p_plugin_component.py#L56

i think the test will need to be modified a bit since we can't wrap the np.int32 in a 'NTScalar'?

@nstelter-slac nstelter-slac self-requested a review October 28, 2024 23:22
@slactjohnson
Copy link
Contributor Author

@nstelter-slac I still intend to add a test, the last week has just been very busy. I'll try to do that by the end of the week.

@slactjohnson
Copy link
Contributor Author

@nstelter-slac This seemed to work, though I admit I'm a little out of my depth here.

Not sure why some of the CI runs failed. I didn't see an option for me to try re-running them.

@slactjohnson
Copy link
Contributor Author

Looks like someone kicked the tests, and they passed. Thanks!
Waiting for an approval of the newly added test prior to merging.

@@ -51,6 +51,7 @@ def generate_control_variables(value):
1,
),
(NTEnum().wrap({"index": 0, "choices": ["YES", "NO", "MAYBE"]}), False, 0, 2),
(NTScalar("i").wrap({"value": np.int32(10)}), False, np.int32(10), 1),
Copy link
Collaborator

@nstelter-slac nstelter-slac Nov 18, 2024

Choose a reason for hiding this comment

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

it seems like NTScalar.wrap converts the np.int32 into just a python int and it gets passed into the testcase, which is b4 the testcase can try to test it. which also means the if on line 82 is not called, (u can add prints to see this and run pytest with -s arg to see print output in terminal)

if we change line 60 to not require a Value type, by having just
value_to_send,
we can actually pass the raw np.int32 into the testcase, but then the testcase fails since send_new_value function expects a Value type (which doesn't seem to support having a wrapped np.integer type, it just converts to python int)

im curious to debug what happens when using this fix with the real pydm screen, and why it doesnt hit this issue? Do you have a screen calling a PV using an np.integer we could use to debug?

Copy link
Collaborator

Choose a reason for hiding this comment

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

also so sorry for long delay on this review!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nstelter-slac Sorry for the long (long) delay in my reply. I had a long vacation through December, but I'm spinning back up now.

I think my particular use case is described in the issue related to this PR, but I'm happy to help debug further if I can. I haven't seen this occur anywhere else. An example of how I'm trying to index out values from an NTTable is here: https://github.com/pcdshub/opcpa-tpr-config/blob/master/opcpa_tpr_config/widgets.py#L161-L166

At this point I'm a little confused about what to do with the test case; how would you like me to proceed?

Copy link
Collaborator

@nstelter-slac nstelter-slac Jan 23, 2025

Choose a reason for hiding this comment

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

hello!

ok i stepped thru the code with example NTTable and i understand things now

i propose we make 2 minor changes and then merge this in right away! (will get included in upcoming pydm release)

  1. support numpy float arrays in NTTable by adding the following to p4p_plugin_component.py:
elif isinstance(new_value, np.float32):
    self.new_value_signal[float].emit(float(new_value))
elif isinstance(new_value, np.float64):
    self.new_value_signal[float].emit(float(new_value))
  1. to hit the fix in a test we'd need testcase with NTTable that has numpy int array in it. And i think that needs to use NTTable().wrap to do, but i tried this and had trouble getting it to work as i wanted.

    so for sake of merging i say we dont have a test rn and instead:

    remove the check here thats never true (b/c of the NTScalar.wrap conversion b4) https://github.com/slaclab/pydm/pull/1120/files#diff-ddc8af515570b1d6723e90ebcb5f52bb38c529a4503d039f49b6e7c542b1ac95R82

    and then add a comment like "# can add cases for testing NTTable containing np.integer and np float types arrays here" : at the top of the test function here https://github.com/slaclab/pydm/pull/1120/files#diff-ddc8af515570b1d6723e90ebcb5f52bb38c529a4503d039f49b6e7c542b1ac95R54

again sry this patch got lost in the cracks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @nstelter-slac. I've implemented the changes you requested, and the tests passed.

@nstelter-slac nstelter-slac self-requested a review November 18, 2024 23:29
@nstelter-slac nstelter-slac merged commit 4a10536 into slaclab:master Jan 24, 2025
13 checks passed
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.

Indexing NTTables fails for numpy integers
2 participants