Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for externals #450

Merged
merged 10 commits into from
Jul 17, 2024
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
16 changes: 8 additions & 8 deletions docs/tables/get_functions.tab
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Vensim Vensim example Xmile Xmile example Abstract Syntax Python Translation Vensim comments Xmile comments Python comments
GET XLS DATA "GET XLS DATA('file', 'sheet', 'time_row_or_col', 'cell')" "GetDataStructure('file', 'sheet', 'time_row_or_col', 'cell')" pysd.external.ExtData(...)
GET DIRECT DATA "GET DIRECT DATA('file', 'sheet', 'time_row_or_col', 'cell')" "GetDataStructure('file', 'sheet', 'time_row_or_col', 'cell')" pysd.external.ExtData(...)
GET XLS LOOKUPS "GET XLS LOOKUPS('file', 'sheet', 'x_row_or_col', 'cell')" "GetLookupsStructure('file', 'sheet', 'x_row_or_col', 'cell')" pysd.external.ExtLookup(...)
GET DIRECT LOOKUPS "GET DIRECT LOOKUPS('file', 'sheet', 'x_row_or_col', 'cell')" "GetLookupsStructure('file', 'sheet', 'x_row_or_col', 'cell')" pysd.external.ExtLookup(...)
GET XLS CONSTANTS "GET XLS CONSTANTS('file', 'sheet', 'cell')" "GetConstantsStructure('file', 'sheet', 'cell')" pysd.external.ExtConstant(...)
GET DIRECT CONSTANTS "GET DIRECT CONSTANTS('file', 'sheet', 'cell')" "GetConstantsStructure('file', 'sheet', 'cell')" pysd.external.ExtConstant(...)
GET XLS SUBSCRIPT "GET XLS SUBSCRIPT('file', 'sheet', 'first_cell', 'last_cell', 'prefix')" pysd.external.ExtSubscript(...)
GET DIRECT SUBSCRIPT "GET DIRECT SUBSCRIPT('file', 'sheet', 'first_cell', 'last_cell', 'prefix')" pysd.external.ExtSubscript(...)
GET XLS DATA "GET XLS DATA('file', 'tab', 'time_row_or_col', 'cell')" "GetDataStructure('file', 'tab', 'time_row_or_col', 'cell')" pysd.external.ExtData(...)
GET DIRECT DATA "GET DIRECT DATA('file', 'tab', 'time_row_or_col', 'cell')" "GetDataStructure('file', 'tab', 'time_row_or_col', 'cell')" pysd.external.ExtData(...)
GET XLS LOOKUPS "GET XLS LOOKUPS('file', 'tab', 'x_row_or_col', 'cell')" "GetLookupsStructure('file', 'tab', 'x_row_or_col', 'cell')" pysd.external.ExtLookup(...)
GET DIRECT LOOKUPS "GET DIRECT LOOKUPS('file', 'tab', 'x_row_or_col', 'cell')" "GetLookupsStructure('file', 'tab', 'x_row_or_col', 'cell')" pysd.external.ExtLookup(...)
GET XLS CONSTANTS "GET XLS CONSTANTS('file', 'tab', 'cell')" "GetConstantsStructure('file', 'tab', 'cell')" pysd.external.ExtConstant(...)
GET DIRECT CONSTANTS "GET DIRECT CONSTANTS('file', 'tab', 'cell')" "GetConstantsStructure('file', 'tab', 'cell')" pysd.external.ExtConstant(...)
GET XLS SUBSCRIPT "GET XLS SUBSCRIPT('file', 'tab', 'first_cell', 'last_cell', 'prefix')" pysd.external.ExtSubscript(...)
GET DIRECT SUBSCRIPT "GET DIRECT SUBSCRIPT('file', 'tab', 'first_cell', 'last_cell', 'prefix')" pysd.external.ExtSubscript(...)
13 changes: 10 additions & 3 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
What's New
==========
v3.14.1 (2024/07/XX)
v3.14.1 (2024/07/18)
--------------------
New Features
~~~~~~~~~~~~
Expand All @@ -15,8 +15,11 @@ Bug fixes
~~~~~~~~~
- Support for :py:mod:`numpy` 2. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Allow multiple font styles in var names (:issue:`443`). (`@rogersamso <https://github.com/rogersamso>`_)
- Allow Vensims GET DIRECT/XLS SUBSCRIPT when lastcell is not a cell value (:issue:`443`). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Allow Vensims GET DIRECT/XLS SUBSCRIPT defined with cell range names (:issue:`261`). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Allow Vensims GET DIRECT/XLS SUBSCRIPT when lastcell is not a cell value (:issue:`443`). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Allow Vensims GET DIRECT/XLS SUBSCRIPT defined with cell range names (:issue:`261`). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Translate filenames as raw :py:class:`str` to made them work properly for Windows paths (:issue:`443`). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Improve support for reading :py:class:`pysd.py_backend.external.External` from all the spreadsheet files includying those types from open software ('.odf', '.ods', '.odt'). (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Improve support for reading :py:class:`pysd.py_backend.external.External` from CSV, TAB and any other kind of text file. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)

Documentation
~~~~~~~~~~~~~
Expand All @@ -28,6 +31,10 @@ Internal Changes
~~~~~~~~~~~~~~~~
- Fix CI tests. (`@rogersamso <https://github.com/rogersamso>`_)
- Run CI coverage only on ubuntu and lowest Python. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Rename 'sheet' by 'tab' in :py:class:`pysd.py_backend.external.External` and related functions and classes to follow Vensim's nomenclature. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Add error message when no subscripts are read from :py:class:`pysd.py_backend.external.ExtSubscript` during the model building. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Add error message when a :py:class:`pysd.py_backend.external.External` cell/firstcell is interpreted as cellrange name but the input file is not a spreadsheet. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)
- Improve parsing of quoted arguments in the vensim translator for external lookups and external subscripts. (`@enekomartinmartinez <https://github.com/enekomartinmartinez>`_)

v3.14.0 (2024/04/24)
--------------------
Expand Down
6 changes: 3 additions & 3 deletions pysd/builders/python/python_expressions_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def build(self, arguments: dict) -> Union[BuildAST, None]:
"""
self.component.type = "Lookup"
self.component.subtype = "External"
arguments["params"] = "'%s', '%s', '%s', '%s'" % (
arguments["params"] = "r'%s', '%s', '%s', '%s'" % (
self.file, self.tab, self.x_row_or_col, self.cell
)
final_subs, arguments["subscripts"] =\
Expand Down Expand Up @@ -966,7 +966,7 @@ def build(self, arguments: dict) -> Union[BuildAST, None]:
"""
self.component.type = "Data"
self.component.subtype = "External"
arguments["params"] = "'%s', '%s', '%s', '%s'" % (
arguments["params"] = "r'%s', '%s', '%s', '%s'" % (
self.file, self.tab, self.time_row_or_col, self.cell
)
final_subs, arguments["subscripts"] =\
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def build(self, arguments: dict) -> Union[BuildAST, None]:
"""
self.component.type = "Constant"
self.component.subtype = "External"
arguments["params"] = "'%s', '%s', '%s'" % (
arguments["params"] = "r'%s', '%s', '%s'" % (
self.file, self.tab, self.cell
)
final_subs, arguments["subscripts"] =\
Expand Down
7 changes: 6 additions & 1 deletion pysd/builders/python/subscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ def subscripts(self, abstract_subscripts: List[AbstractSubscriptRange]):
# subscript from file
self._subscripts[sub.name] = ExtSubscript(
file_name=sub.subscripts["file"],
sheet=sub.subscripts["tab"],
tab=sub.subscripts["tab"],
firstcell=sub.subscripts["firstcell"],
lastcell=sub.subscripts["lastcell"],
prefix=sub.subscripts["prefix"],
root=self._root).subscript

if not self._subscripts[sub.name]:
raise ValueError(
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
Loading