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

[CodeStyle][ruff] fix E226, NPY201 #60245

Merged
merged 2 commits into from
Dec 26, 2023

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Dec 21, 2023

PR types

Others

PR changes

Others

Description

修复E226, NPY201存量,注意这些为 preview 功能

Numpy 2.0 适配情况:

  • np.cast -> np. asarray
  • np.trapz -> scipy.interpolate.trapezoid
  • np.in1d -> np.isin
  • np.row_stack -> np.vstack
  • np.cross -> ❓
  • numpy.testing.assert_array_equal 参数位置改变 (但是我看好像只是换了个名字 1.26dev)
  • numpy.testing.assert_array_almost_equal 参数位置改变 (同上 1.26dev)

相关链接:

@gouzil gouzil requested a review from SigureMo December 21, 2023 16:23
Copy link

paddle-bot bot commented Dec 21, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@gouzil gouzil changed the title [CodeStyle][ruff] fix some preview [CodeStyle][ruff] fix E226, NPY201, PLE0704 Dec 21, 2023
SigureMo
SigureMo previously approved these changes Dec 21, 2023
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

PR 描述可以更清晰些,写一些上下文,这里并不仅仅是 CodeStyle 检查,NPY201 还避免了用户使用 NumPy 2.0 的情况下 Paddle 报错的问题,最好链接上:

  • NPY201 文档
  • NumPy 2.0 即将发布的 tracking issue
  • NumPy 2.0 弃用 API 文档,及他们是否有迁移指南

LGTMeow

self.assertEqual(out1, np.cast['int32'](self.rng1.random()))
self.assertEqual(
out1, np.asarray(self.rng1.random(), dtype=np.int32)
)
Copy link
Member

Choose a reason for hiding this comment

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

2023-12-22 00:56:51 ======================================================================
2023-12-22 00:56:51 ERROR: test_static (test_seed_op.TestDropoutWithRandomSeedGenerator)
2023-12-22 00:56:51 ----------------------------------------------------------------------
2023-12-22 00:56:51 Traceback (most recent call last):
2023-12-22 00:56:51   File "/workspace/Paddle/build/test/legacy_test/test_seed_op.py", line 78, in test_static
2023-12-22 00:56:51     self.check_static_result(place=place)
2023-12-22 00:56:51   File "/workspace/Paddle/build/test/legacy_test/test_seed_op.py", line 73, in check_static_result
2023-12-22 00:56:51     out1, np.asarray(self.rng1.random(), dtype=np.int32)
2023-12-22 00:56:51 OverflowError: Python int too large to convert to C long
2023-12-22 00:56:51 
2023-12-22 00:56:51 ----------------------------------------------------------------------
2023-12-22 00:56:51 Ran 3 tests in 0.056s
2023-12-22 00:56:51 
2023-12-22 00:56:51 FAILED (errors=1)

看样子并不能对齐

Copy link
Member

Choose a reason for hiding this comment

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

# Create dictionary of casting functions that wrap sequences
# indexed by type or type character
cast = _typedict()
for key in _concrete_types:
    cast[key] = lambda x, k=key: array(x, copy=False).astype(k)

cast 实现是这样的,直接 astype 可以么?

Copy link
Member Author

Choose a reason for hiding this comment

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

cast 实现是这样的,直接 astype 可以么?

可以

@paddle-bot paddle-bot bot added the contributor External developers label Dec 21, 2023
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Dec 22, 2023
@gouzil gouzil changed the title [CodeStyle][ruff] fix E226, NPY201, PLE0704 [CodeStyle][ruff] fix E226, NPY201 Dec 22, 2023
@SigureMo
Copy link
Member

链接的话,astral-sh/ruff#7702 里的三个链接就很好了,都是非常有用的参考链接

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow

@luotao1 luotao1 merged commit 7b5c0ab into PaddlePaddle:develop Dec 26, 2023
29 checks passed
@gouzil gouzil deleted the ruff_fix_preview_1 branch December 27, 2023 02:45
Wanglongzhi2001 pushed a commit to Wanglongzhi2001/Paddle that referenced this pull request Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants