-
Notifications
You must be signed in to change notification settings - Fork 16
Add unit tests #7
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: ["*"] | ||
| workflow_dispatch: # allows you to trigger manually | ||
|
|
||
| # When this workflow is queued, automatically cancel any previous running | ||
| # or pending jobs from the same branch | ||
| concurrency: | ||
| group: pytest-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash -l {0} | ||
|
|
||
| jobs: | ||
| test: | ||
| name: ${{ matrix.os }} Python ${{ matrix.python-version }} NumPy ${{ matrix.numpy-version}} | ||
| runs-on: ${{ matrix.os}} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest] | ||
| python-version: ["3.11", "3.14"] | ||
| numpy-version: ["2.3.0", latest] | ||
| include: | ||
| # Test oldest supported Python and NumPy versions | ||
| - os: ubuntu-latest | ||
| python-version: "3.8" | ||
| numpy-version: "1.18.0" | ||
| # Test vs. NumPy nightly wheels | ||
| - os: ubuntu-latest | ||
| python-version: "3.14" | ||
| numpy-version: "nightly" | ||
| # Test issues re. preinstalled SSL certificates on different OSes | ||
| - os: windows-latest | ||
| python-version: "3.14" | ||
| numpy-version: latest | ||
| - os: macos-latest | ||
| python-version: "3.14" | ||
| numpy-version: latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install pinned NumPy | ||
| if: matrix.numpy-version != 'latest' && matrix.numpy-version != 'nightly' | ||
| run: python -m pip install numpy==${{ matrix.numpy-version }} | ||
|
|
||
| - name: Install nightly NumPy wheels | ||
| if: matrix.numpy-version == 'nightly' | ||
| run: pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ numpy | ||
|
|
||
| - name: Install package | ||
| run: pip install . | ||
|
|
||
| - name: Smoke test | ||
| run: python -c "import ml_datasets" | ||
|
|
||
| - name: Install test dependencies | ||
| run: pip install pytest | ||
|
|
||
| - name: Run tests | ||
| run: pytest |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from .cifar import cifar | ||
| from .cmu import cmu | ||
| from .dbpedia import dbpedia | ||
| from .imdb import imdb | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # TODO the tests below only verify that the various functions don't crash. | ||
| # Expand them to test the actual output contents. | ||
|
|
||
| import platform | ||
|
|
||
| import pytest | ||
| import numpy as np | ||
|
|
||
| import ml_datasets | ||
|
|
||
| NP_VERSION = tuple(int(x) for x in np.__version__.split(".")[:2]) | ||
|
|
||
| # FIXME warning on NumPy 2.4 when downloading pre-computed pickles: | ||
| # Python or NumPy boolean but got `align=0`. | ||
| # Did you mean to pass a tuple to create a subarray type? (Deprecated NumPy 2.4) | ||
| if NP_VERSION >= (2, 4): | ||
| np_24_deprecation = pytest.mark.filterwarnings( | ||
| "ignore::numpy.exceptions.VisibleDeprecationWarning", | ||
|
|
||
| ) | ||
| else: | ||
| # Note: can't use `condition=NP_VERSION >= (2, 4)` on the decorator directly | ||
| # as numpy.exceptions did not exist in old NumPy versions. | ||
| np_24_deprecation = lambda x: x | ||
|
|
||
|
|
||
| @np_24_deprecation | ||
| def test_cifar(): | ||
| (X_train, y_train), (X_test, y_test) = ml_datasets.cifar() | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="very slow download") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it's always going to be skipped, why add the test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To inform whoever reads it next that today the whole feature is functionally unusable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make that clear in the message or with a FIXME comment? |
||
| def test_cmu(): | ||
| train, dev = ml_datasets.cmu() | ||
|
|
||
|
|
||
| def test_dbpedia(): | ||
| train, dev = ml_datasets.dbpedia() | ||
|
|
||
|
|
||
| def test_imdb(): | ||
| train, dev = ml_datasets.imdb() | ||
|
|
||
|
|
||
| @np_24_deprecation | ||
| def test_mnist(): | ||
| (X_train, y_train), (X_test, y_test) = ml_datasets.mnist() | ||
|
|
||
|
|
||
| @pytest.mark.xfail(reason="403 Forbidden") | ||
| def test_quora_questions(): | ||
| train, dev = ml_datasets.quora_questions() | ||
|
|
||
|
|
||
| @np_24_deprecation | ||
| def test_reuters(): | ||
| (X_train, y_train), (X_test, y_test) = ml_datasets.reuters() | ||
|
|
||
|
|
||
| @pytest.mark.xfail(platform.system() == "Windows", reason="path issues") | ||
| def test_snli(): | ||
| train, dev = ml_datasets.snli() | ||
|
|
||
|
|
||
| @pytest.mark.xfail(reason="no default path") | ||
| def test_stack_exchange(): | ||
| train, dev = ml_datasets.stack_exchange() | ||
|
|
||
|
|
||
| def test_ud_ancora_pos_tags(): | ||
| (train_X, train_y), (dev_X, dev_y) = ml_datasets.ud_ancora_pos_tags() | ||
|
|
||
|
|
||
| @pytest.mark.xfail(reason="str column where int expected") | ||
| def test_ud_ewtb_pos_tags(): | ||
| (train_X, train_y), (dev_X, dev_y) = ml_datasets.ud_ewtb_pos_tags() | ||
|
|
||
|
|
||
| @pytest.mark.xfail(reason="no default path") | ||
| def test_wikiner(): | ||
| train, dev = ml_datasets.wikiner() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [tool.pytest.ini_options] | ||
| addopts = "--strict-markers --strict-config -v -r sxfE --color=yes --durations=10" | ||
| xfail_strict = true | ||
| filterwarnings = [ | ||
| "error", | ||
| # FIXME spurious random download warnings; will cause trouble in downstream CI | ||
| "ignore:Implicitly cleaning up <HTTPError 403:ResourceWarning", | ||
| "ignore:unclosed <socket.socket:ResourceWarning", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| cloudpickle>=2.2 | ||
| numpy>=1.7.0 | ||
| numpy>=1.18 | ||
| scipy>=1.7.0 | ||
| tqdm>=4.10.0,<5.0.0 | ||
| # Our libraries | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just re-saving the pickle files with numpy 2.4 will fix this. But then you'd need to replace the files in the AWS bucket...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. I'd open a follow-up ticket but the issues tab has been disabled for this repo.