Skip to content

Commit 16599b5

Browse files
Refactor _get_csv_engine: single return point for C engine default
Consolidate multiple "return c" branches into a single fallthrough by expressing the pyarrow compatibility check as a positive condition (is_compatible) instead of multiple negative early returns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0116ca3 commit 16599b5

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

pyathena/pandas/result_set.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,27 +320,32 @@ def _get_csv_engine(
320320
"""Determine the appropriate CSV engine based on configuration and compatibility.
321321
322322
Args:
323-
file_size_bytes: Size of the CSV file in bytes.
323+
file_size_bytes: Size of the CSV file in bytes. Only used for PyArrow
324+
compatibility checks (minimum file size threshold).
324325
chunksize: Chunksize parameter (overrides self._chunksize if provided).
325326
326327
Returns:
327328
CSV engine name ('pyarrow', 'c', or 'python').
328329
"""
329-
if self._engine in ("c", "python"):
330-
return self._engine
330+
if self._engine == "python":
331+
return "python"
331332

333+
# Use PyArrow only when explicitly requested and all compatibility
334+
# checks pass; otherwise fall through to the C engine default.
332335
if self._engine == "pyarrow":
333336
effective_chunksize = chunksize if chunksize is not None else self._chunksize
334-
if effective_chunksize is not None or self._quoting != 1 or self.converters:
335-
return "c"
336-
if file_size_bytes is not None and file_size_bytes < self.PYARROW_MIN_FILE_SIZE_BYTES:
337-
return "c"
338-
try:
339-
return self._get_available_engine(["pyarrow"])
340-
except ImportError:
341-
return "c"
337+
is_compatible = (
338+
effective_chunksize is None
339+
and self._quoting == 1
340+
and not self.converters
341+
and (file_size_bytes is None or file_size_bytes >= self.PYARROW_MIN_FILE_SIZE_BYTES)
342+
)
343+
if is_compatible:
344+
try:
345+
return self._get_available_engine(["pyarrow"])
346+
except ImportError:
347+
pass
342348

343-
# "auto" or unknown → C engine (same as pandas default)
344349
return "c"
345350

346351
def _get_available_engine(self, engine_candidates: list[str]) -> str:

0 commit comments

Comments
 (0)