Skip to content

Commit a84dde2

Browse files
authored
#168 Merge pull request from astropenguin/astropenguin/issue167
Update supported Python versions
2 parents 677197b + b913052 commit a84dde2

File tree

14 files changed

+567
-546
lines changed

14 files changed

+567
-546
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM python:3.11-slim
22

33
ENV PATH=$PATH:/root/.local/bin
44
ENV POETRY_VIRTUALENVS_CREATE=false
5-
ENV POETRY_VERSION=1.2.2
5+
ENV POETRY_VERSION=1.6.1
66

77
RUN apt-get update \
88
&& apt-get install -y curl git \

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
python: ["3.8", "3.9", "3.10", "3.11"]
20+
python: ["3.9", "3.10", "3.11"]
2121
steps:
2222
- uses: actions/checkout@v3
2323
- uses: actions/setup-python@v4
@@ -34,5 +34,5 @@ jobs:
3434
- name: Test code's execution (pytest)
3535
run: pytest -v tests
3636
- name: Test docs' building (Sphinx)
37-
if: ${{ contains('3.10, 3.11', matrix.python) }}
37+
if: ${{ matrix.python != '3.9' }}
3838
run: docs/build

pandas_dataclasses/core/api.py

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

44
# standard library
55
from types import FunctionType
6-
from typing import Any, Callable, Dict, Hashable, Iterable, Optional, Tuple, overload
6+
from typing import Any, Callable, Hashable, Iterable, Optional, overload
77

88

99
# dependencies
@@ -193,9 +193,9 @@ def asseries(obj: Any, *, factory: Any = None) -> Any:
193193
return squeeze(series)
194194

195195

196-
def get_attrs(spec: Spec) -> Dict[Hashable, Any]:
196+
def get_attrs(spec: Spec) -> dict[Hashable, Any]:
197197
"""Derive attributes from a specification."""
198-
data: Dict[Hashable, Any] = {}
198+
data: dict[Hashable, Any] = {}
199199

200200
for field in spec.fields.of(Tag.ATTR):
201201
data.update(items(field))
@@ -217,9 +217,9 @@ def get_columns(spec: Spec) -> Optional[pd.MultiIndex]:
217217
)
218218

219219

220-
def get_data(spec: Spec) -> Dict[Hashable, Any]:
220+
def get_data(spec: Spec) -> dict[Hashable, Any]:
221221
"""Derive data from a specification."""
222-
data: Dict[Hashable, Any] = {}
222+
data: dict[Hashable, Any] = {}
223223

224224
for field in spec.fields.of(Tag.DATA):
225225
for key, val in items(field):
@@ -233,7 +233,7 @@ def get_index(spec: Spec) -> Optional[pd.MultiIndex]:
233233
if not (fields := spec.fields.of(Tag.INDEX)):
234234
return None
235235

236-
data: Dict[Hashable, Any] = {}
236+
data: dict[Hashable, Any] = {}
237237

238238
for field in fields:
239239
for key, val in items(field):
@@ -251,12 +251,12 @@ def ensure(data: Any, dtype: Optional[str]) -> Any:
251251
data = [data]
252252

253253
if isinstance(data, (pd.Index, pd.Series)):
254-
return type(data)(data, dtype=dtype, copy=False)
254+
return type(data)(data, dtype=dtype, copy=False) # type: ignore
255255
else:
256256
return pd.array(data, dtype=dtype, copy=False)
257257

258258

259-
def items(field: Field) -> Iterable[Tuple[Hashable, Any]]:
259+
def items(field: Field) -> Iterable[tuple[Hashable, Any]]:
260260
"""Generate default(s) of a field specification."""
261261
if field.has(Tag.MULTIPLE):
262262
yield from field.default.items()

pandas_dataclasses/core/specs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import Field as Field_, dataclass, fields as fields_, replace
66
from functools import lru_cache
77
from itertools import repeat
8-
from typing import Any, Callable, Hashable, Literal, Optional, Tuple, Union
8+
from typing import Any, Callable, Hashable, Literal, Optional, Union
99

1010

1111
# dependencies
@@ -25,7 +25,7 @@ class Field:
2525
name: Union[Hashable, HashDict]
2626
"""Name of the field data."""
2727

28-
tags: Tuple[Tag, ...] = ()
28+
tags: tuple[Tag, ...] = ()
2929
"""Tags of the field."""
3030

3131
type: Optional[Any] = None
@@ -50,7 +50,7 @@ def update(self, obj: Any) -> Self:
5050
)
5151

5252

53-
class Fields(Tuple[Field, ...]):
53+
class Fields(tuple[Field, ...]):
5454
"""List of field specifications with selectors."""
5555

5656
def of(self, tag: Tag) -> Self:
@@ -104,7 +104,7 @@ def __matmul__(self, obj: Any) -> Self:
104104

105105

106106
@lru_cache(maxsize=None)
107-
def convert_field(field_: "Field_[Any]") -> Field:
107+
def convert_field(field_: Field_[Any]) -> Field:
108108
"""Convert a dataclass field to a field specification."""
109109
return Field(
110110
id=field_.name,

pandas_dataclasses/core/tagging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from functools import reduce
77
from itertools import chain, filterfalse
88
from operator import or_
9-
from typing import Any, Iterable, Optional, Tuple
9+
from typing import Annotated, Any, Iterable, Optional
1010

1111

1212
# dependencies
13-
from typing_extensions import Annotated, Self, TypeGuard, get_args, get_origin
13+
from typing_extensions import Self, TypeGuard, get_args, get_origin
1414

1515

1616
class Tag(Flag):
@@ -80,13 +80,13 @@ def get_tagged(
8080
return tagged if keep_annotations else get_args(tagged)[0]
8181

8282

83-
def get_tags(tp: Any, bound: Tag = Tag.ANY) -> Tuple[Tag, ...]:
83+
def get_tags(tp: Any, bound: Tag = Tag.ANY) -> tuple[Tag, ...]:
8484
"""Extract all tags from the first tagged type."""
8585
tagged = get_tagged(tp, bound, True)
8686
return tuple(filter(Tag.creates, get_args(tagged)[1:]))
8787

8888

89-
def get_nontags(tp: Any, bound: Tag = Tag.ANY) -> Tuple[Any, ...]:
89+
def get_nontags(tp: Any, bound: Tag = Tag.ANY) -> tuple[Any, ...]:
9090
"""Extract all except tags from the first tagged type."""
9191
tagged = get_tagged(tp, bound, True)
9292
return tuple(filterfalse(Tag.creates, get_args(tagged)[1:]))

pandas_dataclasses/core/typing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
# standard library
1616
import types
1717
from dataclasses import Field
18-
from typing import Any, Callable, ClassVar, Dict, Hashable, Protocol, TypeVar, Union
18+
from typing import Any, Callable, ClassVar, Hashable, Protocol, TypeVar, Union
1919

2020

2121
# dependencies
2222
from pandas import DataFrame, Series
2323
from typing_extensions import ParamSpec, get_origin
2424

2525

26-
HashDict = Dict[Hashable, Hashable]
26+
HashDict = dict[Hashable, Hashable]
2727
"""Type hint for dictionary of hashable keys and values."""
2828

2929
Pandas = Union[DataFrame, "Series[Any]"]
@@ -48,7 +48,7 @@
4848
class DataClass(Protocol[PAny]):
4949
"""Protocol for any dataclass object."""
5050

51-
__dataclass_fields__: ClassVar[Dict[str, "Field[Any]"]]
51+
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
5252

5353
def __init__(self, *args: PAny.args, **kwargs: PAny.kwargs) -> None:
5454
...
@@ -57,7 +57,7 @@ def __init__(self, *args: PAny.args, **kwargs: PAny.kwargs) -> None:
5757
class DataClassOf(Protocol[TPandas, PAny]):
5858
"""Protocol for any dataclass object with a factory."""
5959

60-
__dataclass_fields__: ClassVar[Dict[str, "Field[Any]"]]
60+
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
6161
__pandas_factory__: Callable[..., TPandas]
6262

6363
def __init__(self, *args: PAny.args, **kwargs: PAny.kwargs) -> None:

pandas_dataclasses/extras/hints.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33

44
# standard library
5-
from typing import Collection, Dict, Hashable
5+
from typing import Annotated, Collection
66

77

88
# dependencies
9-
from typing_extensions import Annotated
109
from ..core.tagging import Tag
1110
from ..core.typing import TAny
1211

@@ -21,5 +20,5 @@
2120
Index = Annotated[Collection[Annotated[TAny, Tag.DTYPE]], Tag.INDEX]
2221
"""Type hint for index fields (``Index[TAny]``)."""
2322

24-
Multiple = Dict[Hashable, Annotated[TAny, Tag.MULTIPLE]]
23+
Multiple = dict[str, Annotated[TAny, Tag.MULTIPLE]]
2524
"""Type hint for multiple-item fields (``Multiple[TAny]``)."""

pandas_dataclasses/extras/new.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# standard library
55
from inspect import signature
66
from types import MethodType
7-
from typing import Any, Callable, ForwardRef, Generic, Type, Union
7+
from typing import Any, Callable, ForwardRef, Generic, Union
88

99

1010
# dependencies
@@ -23,7 +23,7 @@ def __init__(self, fget: Callable[..., Any]) -> None:
2323
def __get__(
2424
self,
2525
obj: Any,
26-
cls: Type[DataClassOf[TPandas, PAny]],
26+
cls: type[DataClassOf[TPandas, PAny]],
2727
) -> Callable[PAny, TPandas]:
2828
return self.fget(cls) # type: ignore
2929

@@ -77,7 +77,7 @@ def get_factory(cls: Any) -> Callable[..., Any]:
7777
raise TypeError("Factory must be callable.")
7878

7979

80-
def get_return(cls: Any) -> Union[Type[Any], str]:
80+
def get_return(cls: Any) -> Union[type[Any], str]:
8181
"""Extract a return type from a class."""
8282
for base in getattr(cls, "__orig_bases__", ()):
8383
if get_origin(base) is not As:

0 commit comments

Comments
 (0)