Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Message equality fails with NaN values for floats/doubles

未关闭
#207 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@Ryanf55 已经在做这个了。

开始于 2024年3月18日。

  • #208 来自 @Ryanf55 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

从 nan-failed-comparison 提交以及报告中所示的失败用例 test_basic_types 开始。跟踪 rosidl_generator_py 用于 float 字段的消息相等性路径,然后运行相关测试,以确认具有相同 NaN 内容的消息比较结果相等。

由索引模型根据 Issue 内容生成。

描述

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • Binaries and Source
  • Version or commit hash:
    • 0.14.4
  • DDS implementation:
    • N/A
  • Client library (if applicable):
    • N/A
Steps to reproduce issue

See the commit on equality which causes the tests to fail on branch nan-failed-comparison

Expected behavior

When floating point values are set to NaN, and the == equality operator is used to check messages are equal, it should return true when two messages have the same contents

Actual behavior

NaN's don't equal themselves, and the message equality evaluates as False.

Additional information

See https://github.com/ros2/rosidl/pull/789#issuecomment-2000037932

I have a fix internally, I just need approval to share it open source.

Test Logs
21: =================================== FAILURES ===================================
21: _______________________________ test_basic_types _______________________________
21: 
21:     def test_basic_types():
21:         msg = BasicTypes()
21:     
21:         # types
21:         assert isinstance(msg.bool_value, bool)
21:         assert isinstance(msg.byte_value, bytes)
21:         assert 1 == len(msg.byte_value)
21:         # for legacy reasons, 'char' from a .msg interface maps to 'uint8'
21:         assert isinstance(msg.char_value, int)
21:         assert isinstance(msg.float32_value, float)
21:         assert isinstance(msg.float64_value, float)
21:         assert isinstance(msg.int8_value, int)
21:         assert isinstance(msg.uint8_value, int)
21:         assert isinstance(msg.int16_value, int)
21:         assert isinstance(msg.uint16_value, int)
21:         assert isinstance(msg.int32_value, int)
21:         assert isinstance(msg.uint32_value, int)
21:         assert isinstance(msg.int64_value, int)
21:         assert isinstance(msg.uint64_value, int)
21:     
21:         # default values
21:         assert msg.bool_value is False
21:         assert bytes([0]) == msg.byte_value
21:         assert 0 == msg.char_value
21:         assert 0.0 == msg.float32_value
21:         assert 0.0 == msg.float64_value
21:         assert 0 == msg.int8_value
21:         assert 0 == msg.uint8_value
21:         assert 0 == msg.int16_value
21:         assert 0 == msg.uint16_value
21:         assert 0 == msg.int32_value
21:         assert 0 == msg.uint32_value
21:         assert 0 == msg.int64_value
21:         assert 0 == msg.uint64_value
21:     
21:         # assignment
21:         msg.bool_value = True
21:         assert msg.bool_value is True
21:         msg.byte_value = b'2'
21:         assert bytes([50]) == msg.byte_value
21:         msg.char_value = 42
21:         assert 42 == msg.char_value
21:         msg.float32_value = 1.125
21:         assert 1.125 == msg.float32_value
21:         msg.float64_value = 1.125
21:         assert 1.125 == msg.float64_value
21:         msg.int8_value = -50
21:         assert -50 == msg.int8_value
21:         msg.uint8_value = 200
21:         assert 200 == msg.uint8_value
21:         msg.int16_value = -1000
21:         assert -1000 == msg.int16_value
21:         msg.uint16_value = 2000
21:         assert 2000 == msg.uint16_value
21:         msg.int32_value = -30000
21:         assert -30000 == msg.int32_value
21:         msg.uint32_value = 60000
21:         assert 60000 == msg.uint32_value
21:         msg.int64_value = -40000000
21:         assert -40000000 == msg.int64_value
21:         msg.uint64_value = 50000000
21:         assert 50000000 == msg.uint64_value
21:     
21:         # out of range
21:         with pytest.raises(AssertionError):
21:             setattr(msg, 'char_value', '\x80')
21:         for i in [8, 16, 32, 64]:
21:             with pytest.raises(AssertionError):
21:                 setattr(msg, 'int%d_value' % i, 2**(i - 1))
21:             with pytest.raises(AssertionError):
21:                 setattr(msg, 'int%d_value' % i, -2**(i - 1) - 1)
21:             with pytest.raises(AssertionError):
21:                 setattr(msg, 'uint%d_value' % i, -1)
21:             with pytest.raises(AssertionError):
21:                 setattr(msg, 'int%d_value' % i, 2**i)
21:         float32_ieee_max_next = numpy.nextafter(3.402823466e+38, math.inf)
21:         with pytest.raises(AssertionError):
21:             setattr(msg, 'float32_value', -float32_ieee_max_next)
21:         with pytest.raises(AssertionError):
21:             setattr(msg, 'float32_value', float32_ieee_max_next)
21:     
21:         # Only run bounds test on system with non-compliant IEEE 754 float64.
21:         # Otherwise the number is implicitly converted to inf.
21:         if sys.float_info.max > 1.7976931348623157e+308:
21:             float64_ieee_max_next = numpy.nextafter(1.7976931348623157e+308, math.inf)
21:             with pytest.raises(AssertionError):
21:                 setattr(msg, 'float64_value', -float64_ieee_max_next)
21:             with pytest.raises(AssertionError):
21:                 setattr(msg, 'float64_value', float64_ieee_max_next)
21:     
21:         # NaN
21:         setattr(msg, 'float32_value', math.nan)
21:         assert math.isnan(msg.float32_value)
21: >       assert msg == msg
21: E       AssertionError: assert rosidl_generator_py.msg.BasicTypes(bool_value=True, byte_value=b'2', char_value=42, float32_value=nan, float64_value=1...6_value=-1000, uint16_value=2000, int32_value=-30000, uint32_value=60000, int64_value=-40000000, uint64_value=50000000) == rosidl_generator_py.msg.BasicTypes(bool_value=True, byte_value=b'2', char_value=42, float32_value=nan, float64_value=1...6_value=-1000, uint16_value=2000, int32_value=-30000, uint32_value=60000, int64_value=-40000000, uint64_value=50000000)
主要语言
EmberScript
星标
26
派生
68
平均合并
1 天 8 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ros2/rosidl_python 的其他 Issue

查看 ros2/rosidl_python 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。