Skip to content

Commit

Permalink
Update check for existing table (#71)
Browse files Browse the repository at this point in the history
* Update check for existing table

A change in sqlalchemy 1.4 changed how to check
whether a table exists. This enables the new check
and the old check, tested on sqlalchemy 1.3 and 1.4.

Co-authored-by: Jordi Aranda <jarandaf@users.noreply.github.com>

* Fix mypy errors

Newer versions of mypy complain when named tuple is passed the wrong name.
Also added types-cachetools as a test dependency to ensure mypy checks pass.

* version bump

Co-authored-by: Jordi Aranda <jarandaf@users.noreply.github.com>
  • Loading branch information
janfreyberg and jarandaf committed Aug 27, 2021
1 parent 250b18d commit be4f805
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -52,6 +52,7 @@ test = [
"black>=19.3b0",
"flake8>=3.7",
"mypy",
"types-cachetools",
]
doc = [
"sphinx>=2.0,<3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/superintendent/__init__.py
Expand Up @@ -4,4 +4,4 @@
from .base import Labeller

__all__ = ["MultiClassLabeller", "ClassLabeller", "Labeller"]
__version__ = "0.5.2"
__version__ = "0.5.3"
17 changes: 13 additions & 4 deletions src/superintendent/distributed/queueing.py
Expand Up @@ -59,7 +59,7 @@ class DatabaseQueue(BaseLabellingQueue):
"""

worker_id = None
item = namedtuple("QueueItem", ["id", "data", "label"])
item = namedtuple("item", ["id", "data", "label"])

def __init__(
self,
Expand All @@ -86,9 +86,18 @@ def __init__(
self.engine = sa.create_engine(connection_string)
self._popped = deque([])

if not self.engine.dialect.has_table(
self.engine, self.data.__tablename__
):
try:
# works with sqlalchemy >= 1.4
table_exists = sa.inspect(self.engine).has_table(
self.data.__tablename__
)
except AttributeError:
# works with sqlalchemy < 1.3
table_exists = self.engine.dialect.has_table(
self.engine, self.data.__tablename__
)

if not table_exists:
self.data.metadata.create_all(bind=self.engine)

try:
Expand Down
2 changes: 1 addition & 1 deletion src/superintendent/queueing/in_memory.py
Expand Up @@ -13,7 +13,7 @@

class SimpleLabellingQueue(BaseLabellingQueue):

item = namedtuple("QueueItem", ["id", "data", "label"])
item = namedtuple("item", ["id", "data", "label"])

def __init__(self, features: Any = None, labels: Any = None):
"""Create an in-memory labelling queue.
Expand Down

0 comments on commit be4f805

Please sign in to comment.