Skip to content

Commit

Permalink
Make ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Nov 3, 2024
1 parent 2b060ef commit 243044a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
6 changes: 2 additions & 4 deletions pyam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ def get_excel_file_with_kwargs(path, **kwargs):
instance along with the remaining keyword arguments (which presumably
will be used for other purposes by the calling function).
"""
EXCEL_FILE_KWS = ('engine', 'storage_options', 'engine_kwargs')
EXCEL_FILE_KWS = ("engine", "storage_options", "engine_kwargs")
kwargs = kwargs.copy()
excel_file_kwargs = {
k: kwargs.pop(k) for k in EXCEL_FILE_KWS if k in kwargs
}
excel_file_kwargs = {k: kwargs.pop(k) for k in EXCEL_FILE_KWS if k in kwargs}
# TODO remove when bumping minimum pandas dependency to >= 2.2
if "engine_kwargs" in excel_file_kwargs and packaging.version.parse(
importlib.metadata.version("pandas")
Expand Down
8 changes: 1 addition & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# has to go first for environment setup reasons

import matplotlib

matplotlib.use("agg")
Expand Down Expand Up @@ -27,12 +28,10 @@
TEST_API = "integration-test"
TEST_API_NAME = "IXSE_INTEGRATION_TEST"


here = Path(__file__).parent
IMAGE_BASELINE_DIR = here / "expected_figs"
TEST_DATA_DIR = here / "data"


TEST_YEARS = [2005, 2010]
TEST_DTS = [datetime(2005, 6, 17), datetime(2010, 7, 21)]
TEST_TIME_STR = ["2005-06-17", "2010-07-21"]
Expand All @@ -43,7 +42,6 @@

EXP_DATETIME_INDEX = pd.DatetimeIndex(["2005-06-17T00:00:00"], name="time")


TEST_DF = pd.DataFrame(
[
["model_a", "scen_a", "World", "Primary Energy", "EJ/yr", 1, 6.0],
Expand All @@ -62,7 +60,6 @@
columns=META_IDX + META_COLS,
)


FULL_FEATURE_DF = pd.DataFrame(
[
["World", "Primary Energy", "EJ/yr", 12, 15],
Expand Down Expand Up @@ -94,7 +91,6 @@
columns=["region", "variable", "unit"] + TEST_YEARS,
)


img = ["IMAGE", "a_scenario"]
msg = ["MESSAGE-GLOBIOM", "a_scenario"]

Expand All @@ -110,7 +106,6 @@
columns=IAMC_IDX + TEST_YEARS,
)


RECURSIVE_DF = pd.DataFrame(
[
["Secondary Energy|Electricity", "EJ/yr", 5, 19.0],
Expand All @@ -122,7 +117,6 @@
columns=["variable", "unit"] + TEST_YEARS,
)


TEST_STACKPLOT_DF = pd.DataFrame(
[
["World", "Emissions|CO2|Energy|Oil", "Mt CO2/yr", 2, 3.2, 2.0, 1.8],
Expand Down
11 changes: 6 additions & 5 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

try:
import python_calamine # noqa: F401

has_calamine = True
except ModuleNotFoundError: # pragma: no cover
has_calamine = False
Expand Down Expand Up @@ -127,9 +128,9 @@ def test_read_xls(test_df_year):


@pytest.mark.skipif(
packaging.version.parse(importlib.metadata.version("pandas")) \
< packaging.version.parse("2.2.0"),
reason="pandas < 2.2.0 has inconsistent support for `engine_kwargs`",
packaging.version.parse(importlib.metadata.version("pandas"))
< packaging.version.parse("2.2.0"),
reason="pandas < 2.2.0 has inconsistent support for `engine_kwargs`",
)
def test_read_xlsx_kwargs(test_df_year):
# Test that kwargs to `IamDataFrame.__init__` are passed to `pd.read_excel`
Expand All @@ -152,8 +153,8 @@ def test_read_xlsx_kwargs(test_df_year):

@pytest.mark.skipif(not has_calamine, reason="Package 'python_calamine' not installed.")
@pytest.mark.skipif(
packaging.version.parse(importlib.metadata.version("pandas")) \
< packaging.version.parse("2.2.0"),
packaging.version.parse(importlib.metadata.version("pandas"))
< packaging.version.parse("2.2.0"),
reason="`engine='calamine' requires pandas >= 2.2.0",
)
def test_read_xlsx_calamine(test_df_year):
Expand Down

0 comments on commit 243044a

Please sign in to comment.