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

Fix AssertionError for numpy.int64 in Variable Initialization #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Hykaruu
Copy link

@Hykaruu Hykaruu commented Jul 16, 2024

This pull request addresses an issue where an AssertionError is thrown when initializing a Variable with a numpy.int64 type value. The error occurs because the current assertion does not recognize numpy.int64 as a valid integer type.

Proposed Fix
This fix updates the assertion to include numpy.int64 as a valid type. This is done by checking for subtypes of int using numpy.issubdtype.
Additionally, the following code was adapted when casting integers to strings.

Here is the updated code:

assert isinstance(value, (str, bytes, int)) or np.issubdtype(type(value), np.integer), "Value must be a string, int, or image (bytes). Got: {}".format(type(value))
if isinstance(value, int) or np.issubdtype(type(value), np.integer):
    value = str(value)

Testing

  • Tested with numpy.int64 values to ensure the assertion no longer fails.

Fix assertion was being thrown when numpy.int64 detected while it shouldn't
Copy link

@TranPhu1999 TranPhu1999 left a comment

Choose a reason for hiding this comment

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

Tested and worked properly

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