Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 7.0.0
rev: 8.0.1
hooks:
- id: isort
- repo: https://github.com/python/black
rev: 25.11.0
rev: 26.3.1
hooks:
- id: black
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage[toml]
black == 24.4.2
black == 26.3.1
pre-commit
pyperf
sphinx
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ classifiers = [
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Operating System :: OS Independent",
]
requires-python = ">=3.10"
requires-python = ">=3.10" # Remember to bump Black's target-version below when updating this.
dependencies = [
"SQLAlchemy >=2.0, <2.1",
"alembic >=1.7",
Expand Down Expand Up @@ -60,6 +60,7 @@ branch = true
ignore_errors = true

[tool.black]
target-version = ["py310"]
line-length = 120
force-exclude = '\.git|version.py'

Expand Down
2 changes: 1 addition & 1 deletion spinedb_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

""" A package to interact with Spine DBs. """
"""A package to interact with Spine DBs."""

from .db_mapping import DatabaseMapping
from .exception import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,15 @@ def alter_tables_after_update():
date = datetime.now(timezone.utc)
conn = op.get_bind()
conn.execute(
text(
"""
text("""
UPDATE next_id
SET
user = :user,
date = :date,
alternative_id = 2,
scenario_id = 1,
scenario_alternative_id = 1
"""
),
"""),
{
"user": user,
"date": date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,19 @@ def insert_into_new_tables():
]
op.bulk_insert(meta.tables["entity_class"], entity_classes)
# Id mappings
obj_cls_to_ent_cls = {
r.object_class_id: r.entity_class_id
for r in conn.execute(
text(
"""
obj_cls_to_ent_cls = {r.object_class_id: r.entity_class_id for r in conn.execute(text("""
SELECT object_class.id AS object_class_id, entity_class.id AS entity_class_id
FROM object_class, entity_class
WHERE entity_class.type_id = 1
AND object_class.name = entity_class.name
"""
)
)
}
rel_cls_to_ent_cls = {
r.relationship_class_id: r.entity_class_id
for r in conn.execute(
text(
"""
"""))}
rel_cls_to_ent_cls = {r.relationship_class_id: r.entity_class_id for r in conn.execute(text("""
SELECT relationship_class.id AS relationship_class_id, entity_class.id AS entity_class_id
FROM relationship_class, entity_class
WHERE entity_class.type_id = 2
AND relationship_class.name = entity_class.name
GROUP BY relationship_class_id, entity_class_id
"""
)
)
}
"""))}
temp_relationship_classes = [
{"entity_class_id": r.id, "type_id": 2, "commit_id": r.commit_id}
for r in conn.execute(text("SELECT id, commit_id FROM entity_class WHERE type_id = 2"))
Expand All @@ -195,33 +181,19 @@ def insert_into_new_tables():
]
op.bulk_insert(meta.tables["entity"], entities)
# Id mappings
obj_to_ent = {
r.object_id: r.entity_id
for r in conn.execute(
text(
"""
obj_to_ent = {r.object_id: r.entity_id for r in conn.execute(text("""
SELECT object.id AS object_id, entity.id AS entity_id
FROM object, entity
WHERE entity.type_id = 1
AND object.name = entity.name
"""
)
)
}
rel_to_ent = {
r.relationship_id: r.entity_id
for r in conn.execute(
text(
"""
"""))}
rel_to_ent = {r.relationship_id: r.entity_id for r in conn.execute(text("""
SELECT relationship.id AS relationship_id, entity.id AS entity_id
FROM relationship, entity
WHERE entity.type_id = 2
AND relationship.name = entity.name
GROUP BY relationship_id, entity_id
"""
)
)
}
"""))}
temp_relationships = [
{"entity_id": r.id, "entity_class_id": r.class_id, "type_id": 2, "commit_id": r.commit_id}
for r in conn.execute(text("SELECT id, class_id, commit_id FROM entity WHERE type_id = 2"))
Expand All @@ -236,15 +208,11 @@ def insert_into_new_tables():
"member_class_id": obj_cls_to_ent_cls[r.object_class_id],
"commit_id": r.commit_id,
}
for r in conn.execute(
text(
"""
for r in conn.execute(text("""
SELECT r.id, r.class_id, r.dimension, o.class_id AS object_class_id, r.object_id, r.commit_id
FROM relationship AS r, object AS o
WHERE r.object_id = o.id
"""
)
)
"""))
]
op.bulk_insert(meta.tables["relationship_entity"], relationship_entities)
# Return metadata and id mappings
Expand Down Expand Up @@ -309,25 +277,21 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
{"entity_class_id": entity_class_id, "object_class_id": object_class_id},
)
conn.execute(
text(
"""
text("""
UPDATE parameter_definition SET entity_class_id = :entity_class_id
WHERE object_class_id = :object_class_id
"""
),
"""),
{
"entity_class_id": entity_class_id,
"object_class_id": object_class_id,
},
)
for relationship_class_id, entity_class_id in rel_cls_to_ent_cls.items():
conn.execute(
text(
"""
text("""
UPDATE parameter_definition SET entity_class_id = :entity_class_id
WHERE relationship_class_id = :relationship_class_id
"""
),
"""),
{
"entity_class_id": entity_class_id,
"relationship_class_id": relationship_class_id,
Expand All @@ -343,12 +307,10 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
)
entity_class_id = ent_to_ent_cls[entity_id]
conn.execute(
text(
"""
text("""
UPDATE parameter_value SET entity_id = :entity_id, entity_class_id = :entity_class_id
WHERE object_id = :object_id
"""
),
"""),
{
"entity_id": entity_id,
"entity_class_id": entity_class_id,
Expand All @@ -358,12 +320,10 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
for relationship_id, entity_id in rel_to_ent.items():
entity_class_id = ent_to_ent_cls[entity_id]
conn.execute(
text(
"""
text("""
UPDATE parameter_value SET entity_id = :entity_id, entity_class_id = :entity_class_id
WHERE relationship_id = :relationship_id
"""
),
"""),
{
"entity_id": entity_id,
"entity_class_id": entity_class_id,
Expand All @@ -383,8 +343,7 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
user = "alembic"
date = datetime.now(timezone.utc)
conn.execute(
text(
"""
text("""
UPDATE next_id
SET
user = :user,
Expand All @@ -393,8 +352,7 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
entity_type_id = 3,
entity_class_id = :entity_class_id,
entity_id = :entity_id
"""
),
"""),
{
"user": user,
"date": date,
Expand Down
1 change: 1 addition & 0 deletions spinedb_api/arrow_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
This is highly experimental API.

"""

from collections import defaultdict
from collections.abc import Callable, Iterable
import datetime
Expand Down
1 change: 1 addition & 0 deletions spinedb_api/dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
).subquery()
df = fetch_as_dataframe(db_map, final_query, maps)
"""

from __future__ import annotations
import collections
from typing import Any, Union
Expand Down
Loading
Loading