Skip to content

Bug: Index.save method raise TypeError on Path argument #174

Closed

Description

@alexbarev

Describe the bug

Index.save method has following declaration: save(path: Optional[PathLike] = None). From python docs Path implements PathLike protocol. So I expected that passing Path object is fine, but I got an error.

TypeError: save(): incompatible function arguments. The following argument types are supported:
    1. (self: usearch.compiled.Index, path: str) -> None
Invoked with: <usearch.compiled.Index object at 0x7f5955d810b0>, PosixPath('index.usearch')

I recommend to use either str type annotation or add support for Path objects: e.g. just calling str(path).

Steps to reproduce

import numpy as np
from pathlib import Path
from usearch.index import Index

index = Index(ndim=3)
vector = np.array([0.2, 0.6, 0.4])
index.add(42, vector)
index.save(Path("index.usearch"))

Expected behavior

File "index.usearch" created.

USearch version

0.22.3

Operating System

Ubuntu 20.04.6

Hardware architecture

x86

Which interface are you using?

Python bindings

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bug
    invalid
    on Jul 31, 2023
  2. alexbarev commented on Jul 31, 2023

    @alexbarev
    ContributorAuthor

    I think the most accurate solution is to use os.fspath() method, since PathLike interface has related method as you can see from python repo.

  3. ashvardanian commented on Jul 31, 2023

    @ashvardanian
    Member

    That's a valid suggestion. Already on it!

  4. added a commit that references this issue on Jul 31, 2023
    7743709
  5. ashvardanian commented on Jul 31, 2023

    @ashvardanian
    Member

    Thanks, @AleksandrKent! Fixed, coming in the next release!

  6. added a commit that references this issue on Aug 5, 2023
  7. ashvardanian commented on Aug 5, 2023

    @ashvardanian
    Member

    🎉 This issue has been resolved in version 0.23.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

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

Metadata

Metadata

Labels

buginvalidreleased

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions