Skip to content

NCBITaxa() breaks when pathlib Path is used as an input argument #809

Description

@GravityCore

etetoolkit version used: 3.1.3, but is also seen from the code of the problematic script of ete4 at the time of writing

ncbiquery.py NCBITaxa() does not support pathlib's Path() as a value for dbfile argument, because of the line where "+" sign used to concatenate the value without checking nor converting it first to string. That function's documentation nor type hints do not state that string has to be entered, so that needs updating as well.

Problem also exists in other scripts such as gtdbquery.py (seen from the quick search result)

Error log:

2026-06-08 14:12:31	ERROR	__main__:68	An error has been caught in function '<module>', process 'MainProcess' (3576974), thread 'MainThread' (123385250615424):
Traceback (most recent call last):

...
  File "/my/path/workflow/scripts/get_plant_symbionts.py", line 52, in main
    ncbi = NCBITaxa(dbfile=ete_db_fpath, taxdump_file=ncbi_taxdump_fpath)
           │               │                          └ PosixPath('resources/ncbi_taxdump/taxdump.tar.gz')
           │               └ PosixPath('resources/tools/etetoolkit/taxa.sqlite')
           └ <class 'ete3.ncbi_taxonomy.ncbiquery.NCBITaxa'>

  File "/my/path/.venv/lib/python3.12/site-packages/ete3/ncbi_taxonomy/ncbiquery.py", line 108, in __init__
    self.update_taxonomy_database(taxdump_file)
    │    │                        └ PosixPath('resources/ncbi_taxdump/taxdump.tar.gz')
    │    └ <function NCBITaxa.update_taxonomy_database at 0x70379daac860><ete3.ncbi_taxonomy.ncbiquery.NCBITaxa object at 0x70379c763e30>
  File "/my/path/.venv/lib/python3.12/site-packages/ete3/ncbi_taxonomy/ncbiquery.py", line 133, in update_taxonomy_database
    update_db(self.dbfile, taxdump_file)
    │         │    │       └ PosixPath('resources/ncbi_taxdump/taxdump.tar.gz')
    │         │    └ PosixPath('resources/tools/etetoolkit/taxa.sqlite')
    │         └ <ete3.ncbi_taxonomy.ncbiquery.NCBITaxa object at 0x70379c763e30><function update_db at 0x70379daad260>
  File "/my/path/.venv/lib/python3.12/site-packages/ete3/ncbi_taxonomy/ncbiquery.py", line 782, in update_db
    pickle.dump(prepostorder, open(dbfile+'.traverse.pkl', "wb"), 2)
    │      │    │                  └ PosixPath('resources/tools/etetoolkit/taxa.sqlite')
    │      │    └ [1, 10239, 12333, 12340, 12347, 12366, 12368, 12371, 12374, 12375, 12386, 12388, 12392, 12403, 12404, 12405, 12406, 12408, 12...
    │      └ <built-in function dump><module 'six.moves.cPickle' (<six._SixMetaPathImporter object at 0x70379f3570e0>)>

TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions