Skip to content

Commit

Permalink
Merge pull request #79 from oemof/feature/tabular-version-to-metadata
Browse files Browse the repository at this point in the history
Write tabular version to metadata
  • Loading branch information
jnnr committed Jan 17, 2023
2 parents 005fdac + 4e73d47 commit 8e3c229
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/oemof/tabular/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
)
with open(FOREIGN_KEY_DESCRIPTORS_FILE, "r") as fk_descriptors_file:
FOREIGN_KEY_DESCRIPTORS = json.load(fk_descriptors_file)

supported_oemof_tabular_versions = [None, "0.0.1", "0.0.2", "0.0.3"]
2 changes: 2 additions & 0 deletions src/oemof/tabular/datapackage/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import toml
from datapackage import Package, Resource

from oemof.tabular import __version__ as oemof_tabular_version
from oemof.tabular.config import config


Expand Down Expand Up @@ -94,6 +95,7 @@ def infer_metadata(
p = Package()
p.descriptor["name"] = package_name
p.descriptor["profile"] = "tabular-data-package"
p.descriptor["oemof_tabular_version"] = oemof_tabular_version
p.commit()
if not os.path.exists("resources"):
os.makedirs("resources")
Expand Down
13 changes: 13 additions & 0 deletions src/oemof/tabular/datapackage/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import collections.abc as cabc
import json
import re
import warnings
from decimal import Decimal
from itertools import chain, groupby, repeat

import datapackage as dp
import pandas as pd
from oemof.network.network import Bus, Component

from oemof.tabular.config.config import supported_oemof_tabular_versions

from ..tools import HSN, raisestatement, remap

DEFAULT = object()
Expand Down Expand Up @@ -136,6 +139,16 @@ def deserialize_energy_system(cls, path, typemap={}, attributemap={}):
empty.read = lambda *xs, **ks: ()
empty.headers = ()

# check version that was used to create metadata
oemof_tabular_version = package.descriptor.get("oemof_tabular_version")

if oemof_tabular_version not in supported_oemof_tabular_versions:
warnings.warn(
f"Version of datapackage '{oemof_tabular_version}' is not "
f"supported. These versions are supported: "
f"{supported_oemof_tabular_versions}"
)

def parse(s):
return json.loads(s) if s else {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"profile": "tabular-data-package",
"name": "oemof-tabular-dispatch-example",
"oemof_tabular_version": "0.0.3",
"resources": [
{
"path": "data/elements/bus.csv",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"profile": "tabular-data-package",
"name": "oemof-tabular-foreignkeys-examples",
"oemof_tabular_version": "0.0.3",
"resources": [
{
"path": "data/elements/bus.csv",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"profile": "tabular-data-package",
"name": "renpass-invest-example",
"oemof_tabular_version": "0.0.3",
"resources": [
{
"path": "data/elements/bus.csv",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def compare_json_files(file_1, file_2, ignored=None):

if not lines_1 == lines_2:
raise AssertionError(
"Failed matching lp_file_1 with lp_file_2:\n"
"Failed matching json_file_1 with json_file_2:\n"
+ "\n".join(
unified_diff(
lines_1,
Expand Down

0 comments on commit 8e3c229

Please sign in to comment.