Skip to content

Commit 1085d98

Browse files
committed
Follow function signature of polars.concat for merge_databases
1 parent f52729c commit 1085d98

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/bedrock_ge/gi/db_operations.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections.abc import Iterable
2+
13
import pandas as pd
24

35
from bedrock_ge.gi.schemas import (
@@ -11,8 +13,7 @@
1113

1214

1315
def merge_databases(
14-
target_db: BedrockGIDatabase,
15-
incoming_db: BedrockGIDatabase,
16+
brgi_databases: Iterable[BedrockGIDatabase],
1617
) -> BedrockGIDatabase:
1718
"""Merges the incoming Bedrock GI database into the target Bedrock GI database.
1819
@@ -33,22 +34,36 @@ def merge_databases(
3334
# After merging tables validate them with the schemas from bedrock_ge.gi.schemas and check that foreign keys are correct.
3435
# In case the incoming_db contains tables that are not in the target_db, add them to the target_db.
3536
# The function must return a BedrockGIDatabase object.
36-
merged_project = pd.concat(
37-
[target_db.Project, incoming_db.Project], ignore_index=True
38-
)
39-
ProjectSchema.validate(merged_project)
4037

41-
merged_location = pd.concat(
42-
[target_db.Location, incoming_db.Location], ignore_index=True
43-
)
44-
LocationSchema.validate(merged_location)
45-
check_foreign_key("project_uid", merged_project, merged_location)
38+
# merged_project = pd.concat(
39+
# [target_db.Project, incoming_db.Project], ignore_index=True
40+
# )
41+
# ProjectSchema.validate(merged_project)
42+
43+
# merged_location = pd.concat(
44+
# [target_db.Location, incoming_db.Location], ignore_index=True
45+
# )
46+
# LocationSchema.validate(merged_location)
47+
# check_foreign_key("project_uid", merged_project, merged_location)
48+
49+
# merged_insitu = {}
50+
51+
# Draw inspiration from polars.concat
52+
# https://github.com/pola-rs/polars/blob/py-1.30.0/py-polars/polars/functions/eager.py
53+
54+
dbs = list(brgi_databases)
55+
56+
if not dbs:
57+
msg = "Cannot merge an empty list of Bedrock GI databases."
58+
raise ValueError(msg)
59+
elif len(dbs) == 1 and isinstance(dbs[0], BedrockGIDatabase):
60+
return dbs[0]
4661

47-
merged_insitu = {}
62+
target_db = dbs.pop(0)
4863

4964
merged_db = {
50-
"Project": merged_project,
51-
"Location": merged_location,
65+
"Project": "merged_project",
66+
"Location": "merged_location",
5267
}
5368

5469
# merged_db = BedrockGIDatabase(

0 commit comments

Comments
 (0)