Skip to content

Commit

Permalink
Use dict comprehension
Browse files Browse the repository at this point in the history
  • Loading branch information
phackstock committed May 17, 2023
1 parent 43856d9 commit 934e8c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions nomenclature/codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def to_yaml(self, path=None):
"""

class Dumper(yaml.Dumper):
def increase_indent(self, flow=False, *args, **kwargs):
return super().increase_indent(flow=flow, indentless=False)
def increase_indent(self, flow: bool = False, indentless: bool = False):
return super().increase_indent(flow=flow, indentless=indentless)

# translate to list of nested dicts, replace None by empty field, write to file
stream = (
Expand All @@ -289,11 +289,10 @@ def increase_indent(self, flow=False, *args, **kwargs):
.replace(": nan\n", ":\n")
)

if path is not None:
with open(path, "w") as file:
file.write(stream)
else:
if path is None:
return stream
with open(path, "w") as file:
file.write(stream)

def to_pandas(self, sort_by_code: bool = False) -> pd.DataFrame:
"""Export the CodeList to a :class:`pandas.DataFrame`
Expand Down Expand Up @@ -586,7 +585,7 @@ def hierarchy(self) -> List[str]:
List[str]
"""
return sorted(list(set(v.hierarchy for v in self.mapping.values())))
return sorted(list({v.hierarchy for v in self.mapping.values()}))


class MetaCodeList(CodeList):
Expand Down
2 changes: 1 addition & 1 deletion nomenclature/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)


@validate_arguments(config=dict(arbitrary_types_allowed=True))
@validate_arguments(config={"arbitrary_types_allowed": True})
def process(
df: pyam.IamDataFrame,
dsd: DataStructureDefinition,
Expand Down

0 comments on commit 934e8c6

Please sign in to comment.