From 7a5f71f64100f44aed3175b5b9003c70f79fa1d3 Mon Sep 17 00:00:00 2001 From: laughingman7743 Date: Mon, 6 Jul 2026 10:44:19 +0900 Subject: [PATCH 1/2] Use f-strings for the remaining log messages Convert the %-style logger calls outside the filesystem modules (which were converted in GH-730) to f-strings, unifying the logging style across the codebase. Co-Authored-By: Claude Fable 5 --- pyathena/arrow/result_set.py | 4 ++-- pyathena/pandas/result_set.py | 6 +++--- pyathena/pandas/util.py | 2 +- pyathena/polars/result_set.py | 10 +++++----- pyathena/result_set.py | 2 +- pyathena/s3fs/result_set.py | 2 +- pyathena/spark/common.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pyathena/arrow/result_set.py b/pyathena/arrow/result_set.py index 922159e4..c190a98b 100644 --- a/pyathena/arrow/result_set.py +++ b/pyathena/arrow/result_set.py @@ -315,7 +315,7 @@ def _read_csv(self) -> Table: ), ) except Exception as e: - _logger.exception("Failed to read %s/%s.", bucket, key) + _logger.exception(f"Failed to read {bucket}/{key}.") raise OperationalError(*e.args) from e def _read_parquet(self) -> Table: @@ -333,7 +333,7 @@ def _read_parquet(self) -> Table: dataset = parquet.ParquetDataset(f"{bucket}/{key}", filesystem=self._fs) return dataset.read(use_threads=True) except Exception as e: - _logger.exception("Failed to read %s/%s.", bucket, key) + _logger.exception(f"Failed to read {bucket}/{key}.") raise OperationalError(*e.args) from e def _as_arrow(self) -> Table: diff --git a/pyathena/pandas/result_set.py b/pyathena/pandas/result_set.py index 3e49383b..0585ac57 100644 --- a/pyathena/pandas/result_set.py +++ b/pyathena/pandas/result_set.py @@ -575,7 +575,7 @@ def _read_csv(self) -> TextFileReader | DataFrame: return result except Exception as e: - _logger.exception("Failed to read %s.", self.output_location) + _logger.exception(f"Failed to read {self.output_location}.") raise OperationalError(*e.args) from e def _read_parquet(self, engine) -> DataFrame: @@ -609,7 +609,7 @@ def _read_parquet(self, engine) -> DataFrame: **kwargs, ) except Exception as e: - _logger.exception("Failed to read %s.", self.output_location) + _logger.exception(f"Failed to read {self.output_location}.") raise OperationalError(*e.args) from e def _read_parquet_schema(self, engine) -> tuple[dict[str, Any], ...]: @@ -625,7 +625,7 @@ def _read_parquet_schema(self, engine) -> tuple[dict[str, Any], ...]: dataset = parquet.ParquetDataset(f"{bucket}/{key}", filesystem=self._fs) return to_column_info(dataset.schema) except Exception as e: - _logger.exception("Failed to read schema %s/%s.", bucket, key) + _logger.exception(f"Failed to read schema {bucket}/{key}.") raise OperationalError(*e.args) from e else: raise ProgrammingError("Engine must be `pyarrow`.") diff --git a/pyathena/pandas/util.py b/pyathena/pandas/util.py index 25e3657a..b2b96612 100644 --- a/pyathena/pandas/util.py +++ b/pyathena/pandas/util.py @@ -342,7 +342,7 @@ def to_sql( ) for future in concurrent.futures.as_completed(futures): result = future.result() - _logger.info("to_parquet: %s", result) + _logger.info(f"to_parquet: {result}") ddl = generate_ddl( df=df, diff --git a/pyathena/polars/result_set.py b/pyathena/polars/result_set.py index adc4e2ac..988e2d52 100644 --- a/pyathena/polars/result_set.py +++ b/pyathena/polars/result_set.py @@ -472,7 +472,7 @@ def _read_csv(self) -> pl.DataFrame: df.columns = new_columns return df except Exception as e: - _logger.exception("Failed to read %s.", self.output_location) + _logger.exception(f"Failed to read {self.output_location}.") raise OperationalError(*e.args) from e def _read_parquet(self) -> pl.DataFrame: @@ -499,7 +499,7 @@ def _read_parquet(self) -> pl.DataFrame: **self._kwargs, ) except Exception as e: - _logger.exception("Failed to read %s.", self._unload_location) + _logger.exception(f"Failed to read {self._unload_location}.") raise OperationalError(*e.args) from e def _read_parquet_schema(self) -> tuple[dict[str, Any], ...]: @@ -518,7 +518,7 @@ def _read_parquet_schema(self) -> tuple[dict[str, Any], ...]: schema = lazy_df.collect_schema() return to_column_info(schema) except Exception as e: - _logger.exception("Failed to read schema from %s.", self._unload_location) + _logger.exception(f"Failed to read schema from {self._unload_location}.") raise OperationalError(*e.args) from e def _as_polars(self) -> pl.DataFrame: @@ -658,7 +658,7 @@ def _iter_csv_chunks(self) -> Iterator[pl.DataFrame]: batch.columns = new_columns yield batch except Exception as e: - _logger.exception("Failed to read %s.", self.output_location) + _logger.exception(f"Failed to read {self.output_location}.") raise OperationalError(*e.args) from e def _iter_parquet_chunks(self) -> Iterator[pl.DataFrame]: @@ -686,7 +686,7 @@ def _iter_parquet_chunks(self) -> Iterator[pl.DataFrame]: ) yield from lazy_df.collect_batches(chunk_size=self._chunksize) except Exception as e: - _logger.exception("Failed to read %s.", self._unload_location) + _logger.exception(f"Failed to read {self._unload_location}.") raise OperationalError(*e.args) from e def iter_chunks(self) -> PolarsDataFrameIterator: diff --git a/pyathena/result_set.py b/pyathena/result_set.py index ea1fe974..c24b749f 100644 --- a/pyathena/result_set.py +++ b/pyathena/result_set.py @@ -663,7 +663,7 @@ def _read_data_manifest(self) -> list[str]: Key=key, ) except Exception as e: - _logger.exception("Failed to read %s/%s.", bucket, key) + _logger.exception(f"Failed to read {bucket}/{key}.") raise OperationalError(*e.args) from e else: manifest: str = response["Body"].read().decode("utf-8").strip() diff --git a/pyathena/s3fs/result_set.py b/pyathena/s3fs/result_set.py index 04828c00..d0f93357 100644 --- a/pyathena/s3fs/result_set.py +++ b/pyathena/s3fs/result_set.py @@ -141,7 +141,7 @@ def _init_csv_reader(self) -> None: next(self._csv_reader) except Exception as e: - _logger.exception("Failed to open %s.", path) + _logger.exception(f"Failed to open {path}.") raise OperationalError(*e.args) from e def _fetch(self) -> None: diff --git a/pyathena/spark/common.py b/pyathena/spark/common.py index 836ab56a..d25c0b0f 100644 --- a/pyathena/spark/common.py +++ b/pyathena/spark/common.py @@ -153,7 +153,7 @@ def _exists_session(self, session_id: str) -> bool: isinstance(e, botocore.exceptions.ClientError) and e.response["Error"]["Code"] == "InvalidRequestException" ): - _logger.exception("Session: %s not found.", session_id) + _logger.exception(f"Session: {session_id} not found.") return False raise OperationalError(*e.args) from e else: From cf284ae9155de154a5940f0d85dc7278600f3138 Mon Sep 17 00:00:00 2001 From: laughingman7743 Date: Mon, 6 Jul 2026 10:50:25 +0900 Subject: [PATCH 2/2] Convert the multi-line and dynamic-format log calls missed by the sweep The line-based grep missed a multi-line %-style debug call and an info call built from a dynamically appended format string in pandas/result_set.py; convert both to f-strings. Co-Authored-By: Claude Fable 5 --- pyathena/pandas/result_set.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pyathena/pandas/result_set.py b/pyathena/pandas/result_set.py index 0585ac57..7b4e1136 100644 --- a/pyathena/pandas/result_set.py +++ b/pyathena/pandas/result_set.py @@ -524,9 +524,8 @@ def _read_csv(self) -> TextFileReader | DataFrame: effective_chunksize = self._auto_determine_chunksize(length) if effective_chunksize: _logger.debug( - "Auto-determined chunksize: %s for file size: %s bytes", - effective_chunksize, - length, + f"Auto-determined chunksize: {effective_chunksize} " + f"for file size: {length} bytes" ) csv_engine = self._get_csv_engine(length, effective_chunksize) @@ -565,12 +564,11 @@ def _read_csv(self) -> TextFileReader | DataFrame: # Log performance information for large files if length > self.LARGE_FILE_THRESHOLD_BYTES: mode = "chunked" if effective_chunksize else "full" - msg = "Reading %s bytes from S3 in %s mode using %s engine" - args: tuple[object, ...] = (length, mode, csv_engine) - if effective_chunksize: - msg += " with chunksize=%s" - args = (*args, effective_chunksize) - _logger.info(msg, *args) + chunksize = f" with chunksize={effective_chunksize}" if effective_chunksize else "" + _logger.info( + f"Reading {length} bytes from S3 in {mode} mode " + f"using {csv_engine} engine{chunksize}" + ) return result