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

Modify byte decoding #286

Merged
merged 16 commits into from
Sep 13, 2024
Merged

Modify byte decoding #286

merged 16 commits into from
Sep 13, 2024

Conversation

lukaspie
Copy link
Collaborator

@lukaspie lukaspie commented Sep 11, 2024

Following up on discussions in #283 (comment)

"""Decodes a byte array to string if necessary"""
__error_msg = f"Unsupported type {type(elem)}. Expected bytes, or str."
Copy link
Collaborator

Choose a reason for hiding this comment

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

The idea of the original function was that you can feed all types, and it would just return the same value, and only act on byte strings. Now, you have to include type selection everywhere. I don't see the clear advantage. There is anyways no proper type annotation and checking in these parts of the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, here we can just use byte decoding, so I'll remove the error. We wanted to try something similar in pynxtools, but only for string, bytes, and np arrays, so I got a bit confused. I'll change it back here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it, so now the only changes are a bit of error checking, docs, and a new test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I saw the other PR as well. But there, similarly, a lot of type checking would need to be added everywhere in the code, which I don't clearly see the benefit of.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have also changed that one and removing type checking. I initially misinterpreted what you are using this function for, sorry.

Here, we have the same functionality as before, except list of bytes are also decoded. In the other PR in pynxtools, I am also adding support for decoding np array of strings (because NIAC does not want to have numpy in their requirements).

@lukaspie lukaspie changed the title Strict string check Modify byte decoding Sep 12, 2024
@@ -194,3 +194,41 @@ def test_namefitting_precedence(better_fit, better_ref, worse_fit, worse_ref):
assert nexus.get_nx_namefit(better_fit, better_ref) > nexus.get_nx_namefit(
worse_fit, worse_ref
)

Choose a reason for hiding this comment

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

didn't we wanted to put the test to pynxtools?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is: I cannot just copy all the functionality to pynxtools and just call the function here, then I'll get an import error. But since we don't want numpy here, I ended up splitting the functionality. Here, it checks for bytes and list of bytes and in pynxtools, it calls this function from the nxdl_utils, but on top also performs conversion on np arrays.

Therefore, the tests here do the checking for the bytes and list decoding.

@lukaspie lukaspie merged commit cf56332 into fairmat Sep 13, 2024
7 checks passed
@lukaspie lukaspie deleted the strict-string-check branch September 13, 2024 07:47
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.

4 participants