Skip to content

Conversation

@chalmerlowe
Copy link
Collaborator

@chalmerlowe chalmerlowe commented May 15, 2025

A PytestDeprecationWarning was occurring in several test files because pyarrow, when imported by pytest.importorskip, would fail to import numpy.core.multiarray.

This change addresses the warning by explicitly importing numpy before pytest.importorskip("pyarrow", ...) in the affected test files. This ensures that numpy is fully initialized before pyarrow attempts to use it, resolving the underlying import error.

tests/unit/test_table.py::TestRowIterator::test_to_arrow_w_empty_table
  /repo/python-bigquery/tests/unit/test_table.py:3270: PytestDeprecationWarning: 
  Module 'pyarrow' was found, but when imported by pytest it raised:

      **ImportError('numpy.core.multiarray failed to import')**

  In pytest 9.1 this warning will become an error by default.
  You can fix the underlying problem, or alternatively overwrite this behavior and silence this warning by passing exc_type=ImportError explicitly.
  See https://docs.pytest.org/en/stable/deprecations.html#pytest-importorskip-default-behavior-regarding-importerror
    pyarrow = pytest.importorskip(

A `PytestDeprecationWarning` was occurring in several test files
because `pyarrow`, when imported by `pytest.importorskip`, would fail
to import `numpy.core.multiarray`.

This change addresses the warning by explicitly importing `numpy`
before `pytest.importorskip("pyarrow", ...)` in the affected
test files. This ensures that numpy is fully initialized before
pyarrow attempts to use it, resolving the underlying import error.

I also updated the test execution to use `nox -s unit`, which
correctly sets up the test environment and dependencies, allowing
the tests to pass and confirm the warning is resolved. Pre-existing
failures in `tests/unit/test_magics.py` are unrelated to this change.
@chalmerlowe chalmerlowe self-assigned this May 15, 2025
@chalmerlowe chalmerlowe requested review from a team as code owners May 15, 2025 15:35
@chalmerlowe chalmerlowe requested a review from suzmue May 15, 2025 15:35
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/python-bigquery API. labels May 15, 2025
@chalmerlowe chalmerlowe requested review from tswast and removed request for suzmue May 19, 2025 15:11
@chalmerlowe chalmerlowe merged commit a3d6bf3 into main May 20, 2025
37 of 40 checks passed
@chalmerlowe chalmerlowe deleted the fix-pyarrow-numpy-import-warning branch May 20, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/python-bigquery API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants