Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions pyathena/arrow/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions pyathena/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]:
Expand Down
14 changes: 2 additions & 12 deletions pyathena/polars/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down