Fix AttributeError in is_positive_integer on Python 3.11#903
Fix AttributeError in is_positive_integer on Python 3.11#903bug39 wants to merge 2 commits intogoogle:mainfrom
Conversation
Removes .is_integer() call as 'int' object has no attribute'is_integer.'
wang2yn84
left a comment
There was a problem hiding this comment.
Thank you for the PR! Let's try the following and add a unit test here.
def is_integer_value(x):
return isinstance(x, int) or (
isinstance(x, float) and x.is_integer()
)
Added is_integer_value helper and use it within is_positive_integer; Excludes booleans as a subclass of int
Addressed by adding an is_integer_value helper function, also adding a check that x is not a boolean (is_instance(bool, int) would return True). I'm not sure if you wanted me to include an assert block. Please let me know! |
|
Thank you for the update. Can you add a simple test cover various data types to https://github.com/google/tunix/blob/main/tests/rl/rl_utils_test.py? |
|
And also please squash the commits before merge, thank you! |
|
Hi @bug39, Could you please add a sample test and squash the commits? |
Remove .is_integer() call as int.is_integer() was only added in Python 3.12.
pyproject.toml specifies: requires-python = ">=3.11", yet according to https://docs.python.org/3.12/library/stdtypes.html
int.is_integer()was only added in Python 3.12 for duck-type compatibility with `float.is_integer()Resolves #<902>