这是indexloc提供的服务,不要输入任何密码
Skip to content

[Numpy] Fix some TF test failures introduced by NumPy 2.0 update. #73730

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

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

copybara-service[bot]
Copy link

[Numpy] Fix some TF test failures introduced by NumPy 2.0 update.

This change fixes some common test level errors.

  1. Error type: Out-of-bound python value to numpy data type conversion
    Solutions:
    - If the test is not specifically designed to evaluate overflow
    behavior, modify the values or data types used to ensure they fall
    within the range for the target NumPy data type.
    - Or exclude or modify values that are incompatible with certain data
    types.
    - To retain the previous behavior where out-of-bounds conversions
    resulted in overflow, use np.array(value).astype(dtype) instead of
    np.array(value, dtype=dtype).

  2. Error type: Deprecated NumPy namespaces/APIs
    Solution: Replace deprecated code with the recommended alternatives from
    the NumPy documentation. If the suggested replacement isn't available
    in NumPy 1.x, implement version-specific logic or macros to ensure
    compatibility across different NumPy versions.

  3. Error type: NumPy 2.0 has updated requirements for the array protocol. np.array(obj, copy=False) is no longer supported.
    Solution: Follow the NumPy 2.0 migration guide to address the error: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

  4. Error type: NumPy scalar representations now include a np.type prefix (e.g., np.int64(1) instead of just 1).
    Solutions:
    - Convert the NumPy scalar back to a Python value before printing or
    comparing it. Use methods like .item() or .tolist().
    - Or if it is an AssertionError, update the expected error messages to
    include the np.type prefix for NumPy values.

An additional error: The maximum number of dimensions (and arguments) was increased to 64 https://numpy.org/doc/stable/numpy_2_0_migration_guide.html#increased-maximum-number-of-dimensions. Update the maximum value in the tensor test TFETensorTest.testNumpyTooManyDimensions.

@copybara-service copybara-service bot force-pushed the exported_pr_662141936 branch 4 times, most recently from 4b2fdf8 to ec836f6 Compare August 14, 2024 23:51
This change fixes some common test level errors.

1. Error type: Out-of-bound python value to numpy data type conversion
   Solutions:
       - If the test is not specifically designed to evaluate overflow
         behavior, modify the values or data types used to ensure they fall
         within the range for the target NumPy data type.
       - Or exclude or modify values that are incompatible with certain data
         types.
       - To retain the previous behavior where out-of-bounds conversions
         resulted in overflow, use np.array(value).astype(dtype) instead of
         np.array(value, dtype=dtype).

2. Error type: Deprecated NumPy namespaces/APIs
   Solution: Replace deprecated code with the recommended alternatives from
       the NumPy documentation. If the suggested replacement isn't available
       in NumPy 1.x, implement version-specific logic or macros to ensure
       compatibility across different NumPy versions.

3. Error type: NumPy 2.0 has updated requirements for the __array__ protocol. np.array(obj, copy=False) is no longer supported.
   Solution: Follow the NumPy 2.0 migration guide to address the error: https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

4. Error type: NumPy scalar representations now include a np.type prefix (e.g., np.int64(1) instead of just 1).
   Solutions:
       - Convert the NumPy scalar back to a Python value before printing or
         comparing it. Use methods like .item() or .tolist().
       - Or if it is an AssertionError, update the expected error messages to
         include the np.type prefix for NumPy values.

An additional error: The maximum number of dimensions (and arguments) was increased to 64 https://numpy.org/doc/stable/numpy_2_0_migration_guide.html#increased-maximum-number-of-dimensions. Update the maximum value in the tensor test TFETensorTest.testNumpyTooManyDimensions.

PiperOrigin-RevId: 663106876
@copybara-service copybara-service bot force-pushed the exported_pr_662141936 branch from ec836f6 to b6043f0 Compare August 15, 2024 00:44
@copybara-service copybara-service bot closed this Aug 15, 2024
@copybara-service copybara-service bot merged commit b6043f0 into master Aug 15, 2024
1 check passed
@copybara-service copybara-service bot deleted the exported_pr_662141936 branch August 15, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant