Skip to content

Commit 47dff88

Browse files
Unify _to_date converter and add git workflow guidelines
- 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 <noreply@anthropic.com>
1 parent a2d9c20 commit 47dff88

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ The project supports different cursor implementations for various use cases:
3030

3131
## Development Guidelines
3232

33+
### Git Workflow
34+
35+
**CRITICAL: Never Commit Directly to Master Branch**
36+
- **NEVER** commit directly to the `master` branch
37+
- **ALWAYS** create a feature branch for any changes
38+
- **ALWAYS** create a Pull Request (PR) for review
39+
- Use descriptive branch names (e.g., `feature/add-converter`, `fix/null-handling`)
40+
- Create PRs as drafts using `gh pr create --draft`
41+
3342
### Code Style and Quality
3443

3544
#### Import Guidelines

pyathena/arrow/converter.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
from __future__ import annotations
33

44
import logging
5-
from builtins import isinstance
65
from copy import deepcopy
7-
from datetime import date, datetime
8-
from typing import Any, Callable, Dict, Optional, Type, Union
6+
from typing import Any, Callable, Dict, Optional, Type
97

108
from pyathena.converter import (
119
Converter,
1210
_to_binary,
11+
_to_date,
1312
_to_decimal,
1413
_to_default,
1514
_to_json,
@@ -19,14 +18,6 @@
1918
_logger = logging.getLogger(__name__) # type: ignore
2019

2120

22-
def _to_date(value: Optional[Union[str, datetime]]) -> Optional[date]:
23-
if value is None:
24-
return None
25-
if isinstance(value, datetime):
26-
return value.date()
27-
return datetime.strptime(value, "%Y-%m-%d").date()
28-
29-
3021
_DEFAULT_ARROW_CONVERTERS: Dict[str, Callable[[Optional[str]], Optional[Any]]] = {
3122
"date": _to_date,
3223
"time": _to_time,

pyathena/converter.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from copy import deepcopy
99
from datetime import date, datetime, time
1010
from decimal import Decimal
11-
from typing import Any, Callable, Dict, List, Optional, Type
11+
from typing import Any, Callable, Dict, List, Optional, Type, Union
1212

1313
from dateutil.tz import gettz
1414

@@ -17,10 +17,14 @@
1717
_logger = logging.getLogger(__name__) # type: ignore
1818

1919

20-
def _to_date(varchar_value: Optional[str]) -> Optional[date]:
21-
if varchar_value is None:
20+
def _to_date(value: Optional[Union[str, datetime, date]]) -> Optional[date]:
21+
if value is None:
2222
return None
23-
return datetime.strptime(varchar_value, "%Y-%m-%d").date()
23+
if isinstance(value, datetime):
24+
return value.date()
25+
if isinstance(value, date):
26+
return value
27+
return datetime.strptime(value, "%Y-%m-%d").date()
2428

2529

2630
def _to_datetime(varchar_value: Optional[str]) -> Optional[datetime]:

pyathena/polars/converter.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import logging
55
from copy import deepcopy
6-
from datetime import date, datetime
7-
from typing import Any, Callable, Dict, Optional, Union
6+
from typing import Any, Callable, Dict, Optional
87

98
from pyathena.converter import (
109
Converter,
1110
_to_binary,
11+
_to_date,
1212
_to_default,
1313
_to_json,
1414
_to_time,
@@ -17,16 +17,6 @@
1717
_logger = logging.getLogger(__name__)
1818

1919

20-
def _to_date(value: Optional[Union[str, datetime, date]]) -> Optional[date]:
21-
if value is None:
22-
return None
23-
if isinstance(value, datetime):
24-
return value.date()
25-
if isinstance(value, date):
26-
return value
27-
return datetime.strptime(value, "%Y-%m-%d").date()
28-
29-
3020
_DEFAULT_POLARS_CONVERTERS: Dict[str, Callable[[Optional[str]], Optional[Any]]] = {
3121
"date": _to_date,
3222
"time": _to_time,

0 commit comments

Comments
 (0)