Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Changeassert_allclose to acceptnumpy.timedelta64 asatol#30386

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
riku-sakamoto wants to merge2 commits intonumpy:main
base:main
Choose a base branch
Loading
fromriku-sakamoto:fix_atol_format_in_assert_allclose
Open
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
BUG: Fixassert_allclose to acceptnumpy.timedelta64 asatol
The `:g` float formatting caused a TypeError when `atol` was a`numpy.timedelta64` scalar. This patch falls back to default stringformatting for `numpy.timedelta64` scalar. (See#30382)
  • Loading branch information
@riku-sakamoto
riku-sakamoto committedDec 11, 2025
commit1a3d9156ea918af0312ad57c21046be0354ec48d
11 changes: 11 additions & 0 deletionsnumpy/_core/tests/test_datetime.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2748,6 +2748,17 @@ def test_true_divide_object_by_timedelta(
results = inputs / divisor
assert_array_equal(results, expected)

@pytest.mark.parametrize(
"atol", [np.timedelta64(1, "s"), np.timedelta64(1, "ms")]
)
def test_assert_all_close_with_timedelta_atol(
self, atol: np.timedelta64 | datetime.timedelta
):
# gh-30382
a = np.array([1, 2], dtype="m8[s]")
b = np.array([3, 4], dtype="m8[s]")
with pytest.raises(AssertionError):
np.testing.assert_allclose(a, b, atol=atol)

class TestDateTimeData:

Expand Down
6 changes: 5 additions & 1 deletionnumpy/testing/_private/utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1766,7 +1766,11 @@ def compare(x, y):
equal_nan=equal_nan)

actual, desired = np.asanyarray(actual), np.asanyarray(desired)
header = f'Not equal to tolerance rtol={rtol:g}, atol={atol:g}'
if isinstance(atol, np.timedelta64):
atol_str = str(atol)
else:
atol_str = f"{atol:g}"
header = f'Not equal to tolerance rtol={rtol:g}, atol={atol_str}'
assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
verbose=verbose, header=header, equal_nan=equal_nan,
strict=strict)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp