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 9, 2023
1 parent 676da70 commit 126a5b2
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 @@ -272,8 +272,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 @@ -286,11 +286,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 @@ -589,7 +588,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()}))

def filter(self, hierarchy: str) -> "RegionCodeList":
"""Return a filtered RegionCodeList object
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 126a5b2

Please sign in to comment.