Skip to content

Commit

Permalink
Add create directory argument to write elements / sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
simnh committed Feb 6, 2019
1 parent afcfc79 commit 4bbeebf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/oemof/tabular/datapackage/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def write_geometries(filename, geometries, directory="data/geometries"):


def write_elements(filename, elements, directory="data/elements",
replace=False):
replace=False, create_dir=True):
""" Writes elements to filesystem.
Parameters
Expand All @@ -653,6 +653,8 @@ def write_elements(filename, elements, directory="data/elements",
replace: boolean
If set, existing data will be overwritten. Otherwise integrity of
data (unique indices) will be checked
create_dir: boolean
Create the directory if not exists
Returns
-------
path: string
Expand All @@ -661,6 +663,11 @@ def write_elements(filename, elements, directory="data/elements",

path = os.path.join(directory, filename)

if create_dir:
if not os.path.exists(directory):
print("Path {} does not exist. Creating...".format(directory))
os.makedirs(directory)

if elements.index.name != "name":
elements.index.name = "name"

Expand All @@ -680,7 +687,7 @@ def write_elements(filename, elements, directory="data/elements",


def write_sequences(filename, sequences, directory= "data/sequences",
replace=False):
replace=False, create_dir=True):
""" Writes sequences to filesystem.
Parameters
Expand All @@ -695,6 +702,8 @@ def write_sequences(filename, sequences, directory= "data/sequences",
replace: boolean
If set, existing data will be overwritten. Otherwise integrity of
data (unique indices) will be checked
create_dir: boolean
Create the directory if not exists
Returns
-------
path: string
Expand All @@ -703,6 +712,11 @@ def write_sequences(filename, sequences, directory= "data/sequences",

path = os.path.join(directory, filename)

if create_dir:
if not os.path.exists(directory):
print("Path {} does not exist. Creating...".format(directory))
os.makedirs(directory)

if sequences.index.name != "timeindex":
sequences.index.name = "timeindex"

Expand Down

0 comments on commit 4bbeebf

Please sign in to comment.