Skip to content

Commit 0415bd3

Browse files
committed
fix(sqlite): interpolate pathlib.Path correctly in attach
1 parent 245f482 commit 0415bd3

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

ibis/backends/sqlite/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,25 @@ def column_reflect(inspector, table, column_info):
162162
if type(column_info["type"]) is TIMESTAMP:
163163
column_info["type"] = ISODATETIME()
164164

165-
def attach(
166-
self,
167-
name: str,
168-
path: str | Path,
169-
) -> None:
165+
def attach(self, name: str, path: str | Path) -> None:
170166
"""Connect another SQLite database file to the current connection.
171167
172168
Parameters
173169
----------
174170
name
175171
Database name within SQLite
176172
path
177-
Path to sqlite3 database file
173+
Path to sqlite3 database files
174+
175+
Examples
176+
--------
177+
>>> con1 = ibis.sqlite.connect("original.db")
178+
>>> con2 = ibis.sqlite.connect("new.db")
179+
>>> con1.attach("new", "new.db")
180+
>>> con1.list_tables(database="new")
178181
"""
179182
quoted_name = self.con.dialect.identifier_preparer.quote(name)
180-
self.raw_sql(f"ATTACH DATABASE {path!r} AS {quoted_name}")
183+
self.raw_sql(f"ATTACH DATABASE {str(path)!r} AS {quoted_name}")
181184

182185
def _get_sqla_table(self, name, schema=None, autoload=True):
183186
return sa.Table(

ibis/backends/sqlite/tests/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import uuid
2+
from pathlib import Path
23

34
import numpy as np
45
import pandas.testing as tm
@@ -44,7 +45,7 @@ def test_list_tables(con):
4445
def test_attach_file(dbpath):
4546
client = ibis.sqlite.connect(None)
4647

47-
client.attach('foo', dbpath)
48+
client.attach('foo', Path(dbpath))
4849
client.attach('bar', dbpath)
4950

5051
foo_tables = client.list_tables(database='foo')

0 commit comments

Comments
 (0)