From 6a2c1e4f9d5cc2a0a9ce96ee4dc970bea04c52df Mon Sep 17 00:00:00 2001 From: mferrera Date: Mon, 6 Jan 2025 09:55:25 +0100 Subject: [PATCH] STY: ruff check pandas, pyupgrade --- pyproject.toml | 13 ++++++++++--- src/fmu/dataio/_utils.py | 3 ++- src/fmu/dataio/export/rms/inplace_volumes.py | 8 +++----- src/fmu/dataio/providers/_filedata.py | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ffb7def812..19d11af346 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,12 +101,14 @@ match = '(?!(test_|_)).*\.py' [tool.ruff] line-length = 88 -exclude = ["version.py"] +exclude = ["version.py", "docs/ext/**"] [tool.ruff.lint] ignore = [ "B028", # No explicit `stacklevel` keyword argument found "C901", # mccabe complex-structure + "PD901", # Avoid using the generic variable name `df` for dataframes + "PD011", # Avoid using .values on dataframes (gives false positives) ] select = [ "B", # flake-8-bugbear @@ -116,7 +118,7 @@ select = [ "F", # pyflakes "I", # isort "NPY", # numpy - # "PD", # pandas-vet + "PD", # pandas-vet "PIE", # flake8-pie # "PL", # pylint "Q", # flake8-quotes @@ -125,13 +127,18 @@ select = [ "SIM", # flake8-simplify # "TCH", # flake8-type-checking # "TID", # flake8-tidy-imports - # "UP", # pyupgrade + "UP", # pyupgrade "W", # pylint-warnings ] [tool.ruff.lint.pydocstyle] convention = "google" +[tool.ruff.lint.pyupgrade] +# Preserve types, even if a file imports `from __future__ import annotations`. +# TODO: Remove when Python 3.8 / 3.9 support is deprecated. +keep-runtime-typing = true + [tool.ruff.lint.isort] combine-as-imports = true diff --git a/src/fmu/dataio/_utils.py b/src/fmu/dataio/_utils.py index 160e61e728..dd1f5909b4 100644 --- a/src/fmu/dataio/_utils.py +++ b/src/fmu/dataio/_utils.py @@ -103,7 +103,8 @@ def export_file( if isinstance(out, xtgeo.Polygons): # out.pname = "ID" not working out.get_dataframe(copy=False).rename( - columns={out.pname: "ID"}, inplace=True + columns={out.pname: "ID"}, + inplace=True, # noqa: PD002 ) out.get_dataframe(copy=False).to_csv(file, index=False) elif file_suffix == ".pol" and isinstance(obj, (xtgeo.Polygons, xtgeo.Points)): diff --git a/src/fmu/dataio/export/rms/inplace_volumes.py b/src/fmu/dataio/export/rms/inplace_volumes.py index 3e08daf4f7..f9fea21d39 100644 --- a/src/fmu/dataio/export/rms/inplace_volumes.py +++ b/src/fmu/dataio/export/rms/inplace_volumes.py @@ -114,11 +114,9 @@ def _get_table_from_rms(self) -> pd.DataFrame: """Fetch volumetric table from RMS and convert to pandas dataframe""" _logger.debug("Read values and convert to pandas dataframe...") return pd.DataFrame.from_dict( - ( - self.project.volumetric_tables[self._volume_table_name] - .get_data_table() - .to_dict() - ) + self.project.volumetric_tables[self._volume_table_name] + .get_data_table() + .to_dict() ) @staticmethod diff --git a/src/fmu/dataio/providers/_filedata.py b/src/fmu/dataio/providers/_filedata.py index 242cd717be..90d84b39fc 100644 --- a/src/fmu/dataio/providers/_filedata.py +++ b/src/fmu/dataio/providers/_filedata.py @@ -146,7 +146,7 @@ def _get_filestem(self) -> str: self._get_timepart_for_filename(), ) # join non-empty parts with '--' - filestem = "--".join((p for p in filestem_order if p)) + filestem = "--".join(p for p in filestem_order if p) filestem = self._sanitize_the_filestem(filestem) return filestem.lower()