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][NPY001] replace numpy deprecated type alias #51524

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ repos:
- --ignore-pass-after-docstring
- --ignore-init-module-imports
- --exclude=python/paddle/fluid/[!t]**,python/paddle/fluid/tra**
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --no-cache]
- repo: local
hooks:
- id: pylint-doc-string
Expand Down
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,45 @@ extend_skip_glob = [
"python/paddle/fluid/tests/unittests/npu/**",
"python/paddle/fluid/tests/unittests/mlu/**",
]

[tool.ruff]
exclude = [
"./build",
"./python/paddle/fluid/[!t]**",
"./python/paddle/fluid/tra**",
"./python/paddle/utils/gast/**",
"./python/paddle/fluid/tests/unittests/npu/**",
"./python/paddle/fluid/tests/unittests/mlu/**",
]
target-version = "py37"
select = [
# Pyupgrade
"UP001",
"UP003",
"UP007",
"UP011",
"UP013",
"UP014",
"UP017",
"UP019",
"UP020",
"UP021",
"UP022",
"UP023",
"UP025",
"UP026",
"UP029",
"UP033",
"UP035",
"UP036",

# NumPy-specific rules
"NPY001",
]
unfixable = [
"NPY001"
]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"setup.py" = ["UP036"]
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ def generate_input(shape, op_type):
)
# Paddle mul support bool and TensorRT not
if op_type == "elementwise_mul":
return np.random.random(shape).astype(np.bool)
return np.random.random(shape).astype(np.bool_)

for shape in [[4], [4, 32], [2, 32, 16], [1, 8, 16, 32]]:
for op_type in [
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ def _assert_is_close(
else:
abs_a = 1 if abs_a < 1e-3 else abs_a

if self.dtype == np.bool:
if self.dtype == np.bool_:
diff_mat = np.abs(a ^ b) / abs_a
else:
diff_mat = np.abs(a - b) / abs_a
Expand Down