Skip to content

Commit

Permalink
Fix header reading
Browse files Browse the repository at this point in the history
  • Loading branch information
enekomartinmartinez committed Jul 1, 2024
1 parent 49e3e44 commit 3a294e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pysd/builders/python/subscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def subscripts(self, abstract_subscripts: List[AbstractSubscriptRange]):

if not self._subscripts[sub.name]:
raise ValueError(
"Subscript range empty:\n%s" % sub.subscripts)
f"Subscript range '{sub.name}' empty:\n\t"
+ str(sub.subscripts))
else:
raise ValueError(
f"Invalid definition of subscript '{sub.name}':\n\t"
Expand Down
3 changes: 2 additions & 1 deletion pysd/py_backend/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,9 @@ def get_subscripts_cell(self, row_first, col_first, lastcell):
# read the data
data = read_func(
self.file,
skiprows=row_first-1,
skiprows=row_first,
dtype=object,
header=None,
**read_kwargs
).values

Expand Down
1 change: 1 addition & 0 deletions tests/data/input.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1,2,3,4,5,6,7,8,9,10,
23 changes: 23 additions & 0 deletions tests/pytest_types/external/pytest_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,29 @@ def test_subscript_h2(self, _root):

assert data.subscript == expected

def test_subscript_h_csv(self, _root):
"""
ExtSubscript test for horizontal subscripts
"""
import pysd

file_name = "data/input.csv"
sheet = ""
firstcell = "A1"
lastcell = "1"
prefix = 'h'
expected = ['h1', 'h2', 'h3', 'h4', 'h5',
'h6', 'h7', 'h8', 'h9', 'h10']

data = pysd.external.ExtSubscript(file_name=file_name,
sheet=sheet,
root=_root,
firstcell=firstcell,
lastcell=lastcell,
prefix=prefix)

assert data.subscript == expected

def test_subscript_v(self, _root):
"""
ExtSubscript test for vertical subscripts
Expand Down

0 comments on commit 3a294e4

Please sign in to comment.