From 47dff888dc5eba80fff12a3ed17b053939d2f591 Mon Sep 17 00:00:00 2001 From: laughingman7743 Date: Mon, 5 Jan 2026 01:34:40 +0900 Subject: [PATCH] Unify _to_date converter and add git workflow guidelines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extended base _to_date function to handle Union[str, datetime, date] - Removed duplicate _to_date implementations from arrow and polars converters - Added git workflow guidelines to CLAUDE.md (never commit directly to master) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- CLAUDE.md | 9 +++++++++ pyathena/arrow/converter.py | 13 ++----------- pyathena/converter.py | 12 ++++++++---- pyathena/polars/converter.py | 14 ++------------ 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 1517b58a..c7fadbcd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -30,6 +30,15 @@ The project supports different cursor implementations for various use cases: ## Development Guidelines +### Git Workflow + +**CRITICAL: Never Commit Directly to Master Branch** +- **NEVER** commit directly to the `master` branch +- **ALWAYS** create a feature branch for any changes +- **ALWAYS** create a Pull Request (PR) for review +- Use descriptive branch names (e.g., `feature/add-converter`, `fix/null-handling`) +- Create PRs as drafts using `gh pr create --draft` + ### Code Style and Quality #### Import Guidelines diff --git a/pyathena/arrow/converter.py b/pyathena/arrow/converter.py index f22696c8..f26dbeb3 100644 --- a/pyathena/arrow/converter.py +++ b/pyathena/arrow/converter.py @@ -2,14 +2,13 @@ from __future__ import annotations import logging -from builtins import isinstance from copy import deepcopy -from datetime import date, datetime -from typing import Any, Callable, Dict, Optional, Type, Union +from typing import Any, Callable, Dict, Optional, Type from pyathena.converter import ( Converter, _to_binary, + _to_date, _to_decimal, _to_default, _to_json, @@ -19,14 +18,6 @@ _logger = logging.getLogger(__name__) # type: ignore -def _to_date(value: Optional[Union[str, datetime]]) -> Optional[date]: - if value is None: - return None - if isinstance(value, datetime): - return value.date() - return datetime.strptime(value, "%Y-%m-%d").date() - - _DEFAULT_ARROW_CONVERTERS: Dict[str, Callable[[Optional[str]], Optional[Any]]] = { "date": _to_date, "time": _to_time, diff --git a/pyathena/converter.py b/pyathena/converter.py index d72a612e..bc39419f 100644 --- a/pyathena/converter.py +++ b/pyathena/converter.py @@ -8,7 +8,7 @@ from copy import deepcopy from datetime import date, datetime, time from decimal import Decimal -from typing import Any, Callable, Dict, List, Optional, Type +from typing import Any, Callable, Dict, List, Optional, Type, Union from dateutil.tz import gettz @@ -17,10 +17,14 @@ _logger = logging.getLogger(__name__) # type: ignore -def _to_date(varchar_value: Optional[str]) -> Optional[date]: - if varchar_value is None: +def _to_date(value: Optional[Union[str, datetime, date]]) -> Optional[date]: + if value is None: return None - return datetime.strptime(varchar_value, "%Y-%m-%d").date() + if isinstance(value, datetime): + return value.date() + if isinstance(value, date): + return value + return datetime.strptime(value, "%Y-%m-%d").date() def _to_datetime(varchar_value: Optional[str]) -> Optional[datetime]: diff --git a/pyathena/polars/converter.py b/pyathena/polars/converter.py index b078842e..be3f7cdd 100644 --- a/pyathena/polars/converter.py +++ b/pyathena/polars/converter.py @@ -3,12 +3,12 @@ import logging from copy import deepcopy -from datetime import date, datetime -from typing import Any, Callable, Dict, Optional, Union +from typing import Any, Callable, Dict, Optional from pyathena.converter import ( Converter, _to_binary, + _to_date, _to_default, _to_json, _to_time, @@ -17,16 +17,6 @@ _logger = logging.getLogger(__name__) -def _to_date(value: Optional[Union[str, datetime, date]]) -> Optional[date]: - if value is None: - return None - if isinstance(value, datetime): - return value.date() - if isinstance(value, date): - return value - return datetime.strptime(value, "%Y-%m-%d").date() - - _DEFAULT_POLARS_CONVERTERS: Dict[str, Callable[[Optional[str]], Optional[Any]]] = { "date": _to_date, "time": _to_time,