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

Miscellaneous fixes #238

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ authors = [
{ name="Sam Webster", email="[email protected]" },
{ name="Tom Minka", email="[email protected]" },
{ name="Siddharth Krishna", email="[email protected]" },
{ name="Olexandr Balyk", email="[email protected]" },
{ name="Olexandr Balyk", email="[email protected]" }
siddharth-krishna marked this conversation as resolved.
Show resolved Hide resolved
]
maintainers = [
{ name="Siddharth Krishna", email="[email protected]" },
{ name="Olexandr Balyk", email="[email protected]" },
{ name="Olexandr Balyk", email="[email protected]" }
]
description = 'An open source tool to convert TIMES models specified in Excel a format ready for processing by GAMS'
description = 'An open source tool to convert TIMES models specified in Excel to a format ready for processing by GAMS'
readme = "README.md"
requires-python = ">=3.11"
license = { file = "LICENSE" }
Expand All @@ -28,7 +28,7 @@ classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3"
]
dependencies = [
"GitPython >= 3.1.31, < 3.2",
Expand All @@ -52,7 +52,7 @@ dev = [
]

[project.urls]
Documentation = "https://github.com/etsap-TIMES/xl2times#readme"
Documentation = "https://xl2times.readthedocs.io"
Issues = "https://github.com/etsap-TIMES/xl2times/issues"
Source = "https://github.com/etsap-TIMES/xl2times"

Expand Down
4 changes: 3 additions & 1 deletion xl2times/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def data_years(self) -> set[int]:
data_years = set()
for attributes in [self.attributes, self.uc_attributes]:
if not attributes.empty:
data_years.update(attributes["year"].astype(int).values)
# Index of the year column with non-empty values
index = attributes["year"] != ""
data_years.update(attributes["year"][index].astype(int).values)
# Remove interpolation rules before return
return {y for y in data_years if y >= 1000}

Expand Down
2 changes: 1 addition & 1 deletion xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ def query(
qs.append(f"attribute == '{attribute}'")
if region is not None:
qs.append(f"region == '{region}'")
if year is not None:
if year not in [None, ""]:
qs.append(f"year == {year}")
query_str = " and ".join(qs)
row_idx = table.query(query_str).index
Expand Down
4 changes: 4 additions & 0 deletions xl2times/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,16 @@ def has_negative_patterns(pattern: str) -> bool:


def remove_negative_patterns(pattern: str) -> str:
# Remove trailing commas
pattern = pattern.rstrip(",")
if len(pattern) == 0:
return pattern
return ",".join([word for word in pattern.split(",") if word[0] != "-"])


def remove_positive_patterns(pattern: str) -> str:
# Remove trailing commas
pattern = pattern.rstrip(",")
if len(pattern) == 0:
return pattern
return ",".join([word[1:] for word in pattern.split(",") if word[0] == "-"])
Expand Down
Loading