Skip to content

Migrate Python tests off the deprecated 0.7 call forms #214

Closed

Description

@gouyt13

Problem

0.8 introduced train / set_centroids / add, and the 0.7 forms (positional constructor
options, build, positional add options and others listed in #213) now raise
DeprecationWarning. 0.9 removes them. Many Python tests still use the 0.7 forms only for setup, so they
emit warnings now and will break in 0.9.

Task

Rewrite test setup that uses a deprecated form only to create or fill an index, using the
0.8 API.
This is a tracking issue: one PR per file (or a few small files) is ideal. The maintainers
are migrating the remaining files.

# 0.7 form
index.build(data, centroids, cluster_ids, num_threads=1)
# 0.8 form
index.set_centroids(centroids)
index.add(data, cluster_ids=cluster_ids, num_threads=1)

The migration guide lists
every mapping, including HNSW and SymphonyQG.

Rules

  • Keep each test's intent. A test of 0.7-only behavior with no 0.8 form (such as build
    replacing an index, or validation of max_elements and quantization_bits) moves to
    test_compat_08.py, which Remove the deprecated 0.7 Python call forms #213 deletes; wrap its deprecated calls in that file's quietly
    or single_deprecation. If test_compat_08.py already covers it, delete it instead. Say
    which in the PR. Known cases: test_hnsw.py::test_rejected_rebuild_preserves_index and
    test_zero_capacity_raises, test_symqg.py::test_failed_rebuild_preserves_index,
    test_successful_rebuild_replaces_index and test_invalid_quantization_bits_raises, and
    test_input_boundaries.py::test_build_row_count_diagnostics.
  • Do not change the existing tests in these files: test_compat_08.py, test_txtai_compat.py,
    test_train_api.py, test_symqg_api.py (they test compatibility or equivalence on purpose).
  • HNSW defaults differ: the 0.7 constructor used nbits=8 and the 0.8 one uses nbits=7, so
    pass nbits= explicitly. set_centroids needs HnswIndex(..., num_clusters=len(centroids)),
    while the 0.7 build accepted any number of centroids.
  • max_elements no longer comes from the constructor: a new IvfIndex starts at 0 and grows
    to the stored count, and HnswIndex grows on add. Update expected max_elements values
    and reprs; where a test needs a preallocated capacity, use HnswIndex.resize(n) (see test(python): migrate index count tests to the 0.8 API #226).
  • Pass num_threads explicitly where the old call relied on its default: build defaulted
    to 1 thread, while add defaults to all CPUs. Tests that compare bytes or exact results
    need the same thread count as before.
  • Run the edited file with python -m pytest -W error::DeprecationWarning tests/python/<file>
    to confirm no deprecated call remains; this also catches deprecated constructor forms
    and properties that a search for .build( misses.

Files

Files with tests that fail under -W error::DeprecationWarning at v0.8.2, excluding the four
above.

The seven unchecked files are also changed by #222. #227 also applied the #216 fixes to the
graph cases of test_array_alignment.py and test_thread_counts.py.

Setup and checks: contribution guide, Python changes.

Activity

  1. added this to the 0.9 milestone on Nov 2, 2026
  2. leo062644 commented on Nov 10, 2026

    @leo062644
    Contributor

    I'd like to migrate tests/python/test_index_counts.py to the 0.8 API, preserving its capacity/live/stored-count checks and verifying it with DeprecationWarning treated as an error.

  3. gouyt13 commented on Nov 11, 2026

    @gouyt13
    MemberAuthor

    test_index_counts.py is done in #226, thanks to leo062644.

    The maintainers will migrate the remaining files, so this issue is no longer open for new
    claims. I updated the rules above with what the first migration showed:

    • A test of 0.7-only behavior moves to test_compat_08.py, or is deleted where that file
      already covers it, so every listed file can pass -W error::DeprecationWarning. The known
      cases are listed.
    • HNSW: pass nbits= explicitly (8 by default in 0.7, 7 in 0.8), and pass
      num_clusters=len(centroids) to the constructor before set_centroids.
    • Expected max_elements values and reprs may change, because the 0.8 constructors no longer
      set the capacity; this does not change what the test checks.
  4. self-assigned this
    on Nov 11, 2026
  5. gouyt13 commented on Nov 12, 2026

    @gouyt13
    MemberAuthor

    #227 migrates ten more files, now checked above. Its CI failed twice on graph builds that left one point unreachable, so it also applies the #216 fixes to the graph cases of test_array_alignment.py and test_thread_counts.py. Seven files remain; #222 also changes them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

pythonPull requests that update python code

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions