Skip to content

fix: guard tensorflow import to allow test_nn collection without TF#104

Open
bugparty wants to merge 1 commit into
ddbourgin:masterfrom
bugparty:worktree-agent-a1f242718f48b0914
Open

fix: guard tensorflow import to allow test_nn collection without TF#104
bugparty wants to merge 1 commit into
ddbourgin:masterfrom
bugparty:worktree-agent-a1f242718f48b0914

Conversation

@bugparty
Copy link
Copy Markdown

Summary

  • Guard import tensorflow as tf in numpy_ml/tests/nn_torch_models.py with try/except ImportError so the module can be imported when tensorflow is not installed
  • Wrap all TF-dependent code (WGAN_GP_tf, TFNCELoss, and helper functions param, params_with_name, ReLULayer, LinearLayer, Generator, Discriminator) under if tf is not None:
  • Add @pytest.mark.skipif("tensorflow" not in sys.modules, reason="tensorflow not installed") to test_NCELoss and test_WGAN_GP in test_nn.py
  • TF-dependent imports in test_nn.py are now conditional on tensorflow being in sys.modules

Test plan

  • Verified test_nn.py collects all 41 tests without tensorflow installed
  • Verified test_NCELoss and test_WGAN_GP are properly skipped (reason: "tensorflow not installed")
  • Verified PyTorch-only tests (e.g., test_sigmoid_activation) still pass
  • Verified TFNCELoss and WGAN_GP_tf are not importable when TF is missing

🤖 Generated with Claude Code

Guard the `import tensorflow as tf` in nn_torch_models.py with a
try/except so the module can be imported when tensorflow is not
installed. Wrap all TF-dependent code (WGAN_GP_tf, TFNCELoss, and
their helper functions) under `if tf is not None:`. Add
`@pytest.mark.skipif` decorators to test_NCELoss and test_WGAN_GP
in test_nn.py so they are skipped when tensorflow is unavailable,
while PyTorch-only tests can still be collected and run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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