Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
akihironitta authored Oct 12, 2024
2 parents 6b76443 + 59d4d55 commit d698f26
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Setup
inputs:
python-version:
required: false
default: '3.8'
default: '3.9'
torch-version:
required: false
default: '2.2.0'
Expand All @@ -16,7 +16,7 @@ runs:

steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
check-latest: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9
- name: Install dependencies
run: |
pip install -e '.[full,test]' -f https://download.pytorch.org/whl/cpu
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
hooks:
- id: pyupgrade
name: Upgrade Python syntax
args: [--py38-plus]
args: [--py39-plus]

- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Removed

- Dropped support for Python 3.8 ([#462](https://github.com/pyg-team/pytorch-frame/pull/462))

### Fixed

- Fixed size mismatch `RuntimeError` in `transforms.CatToNumTransform` ([#446](https://github.com/pyg-team/pytorch-frame/pull/446))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ The benchmark script for Hugging Face text encoders is in this [file](https://gi

## Installation

PyTorch Frame is available for Python 3.8 to Python 3.11.
PyTorch Frame is available for Python 3.9 to Python 3.11.

```
pip install pytorch_frame
Expand Down
8 changes: 4 additions & 4 deletions benchmark/data_frame_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import os.path as osp
import time
from typing import Any, Dict, Optional, Tuple
from typing import Any, Optional

import numpy as np
import optuna
Expand Down Expand Up @@ -303,10 +303,10 @@ def test(


def train_and_eval_with_cfg(
model_cfg: Dict[str, Any],
train_cfg: Dict[str, Any],
model_cfg: dict[str, Any],
train_cfg: dict[str, Any],
trial: Optional[optuna.trial.Trial] = None,
) -> Tuple[float, float]:
) -> tuple[float, float]:
# Use model_cfg to set up training procedure
if args.model_type == 'FTTransformerBucket':
# Use LinearBucketEncoder instead
Expand Down
3 changes: 1 addition & 2 deletions benchmark/encoder/encoder_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import time
from argparse import ArgumentParser
from contextlib import nullcontext
from typing import Dict

import torch
from line_profiler import profile
Expand Down Expand Up @@ -115,7 +114,7 @@
}


def make_stype_encoder_dict() -> Dict[stype, StypeEncoder]:
def make_stype_encoder_dict() -> dict[stype, StypeEncoder]:
stype_encoder_dict = {}
for stype_str, encoder_str in args.stype_kv:
encoder_kwargs = encoder_str2encoder_cls_kwargs[encoder_str]
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://download.pytorch.org/whl/cpu/torch-2.0.0%2Bcpu-cp38-cp38-linux_x86_64.whl
https://download.pytorch.org/whl/cpu/torch-2.4.1%2Bcpu-cp39-cp39-linux_x86_64.whl
git+https://github.com/pyg-team/pyg_sphinx_theme.git
2 changes: 1 addition & 1 deletion docs/source/get_started/installation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installation
============

:pyf:`PyTorch Frame` is available for `Python 3.8` to `Python 3.11` on Linux, Windows and macOS.
:pyf:`PyTorch Frame` is available for `Python 3.9` to `Python 3.11` on Linux, Windows and macOS.

Installation via PyPI
---------------------
Expand Down
11 changes: 5 additions & 6 deletions examples/llm_embedding.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import os
import os.path as osp
from typing import List

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -64,10 +63,10 @@ def __init__(self, model: str = "text-embedding-ada-002"):
self.client = OpenAI(api_key=api_key)
self.model = model

def __call__(self, sentences: List[str]) -> Tensor:
def __call__(self, sentences: list[str]) -> Tensor:
from openai import Embedding

items: List[Embedding] = self.client.embeddings.create(
items: list[Embedding] = self.client.embeddings.create(
input=sentences, model=self.model).data
assert len(items) == len(sentences)
embeddings = [
Expand All @@ -87,7 +86,7 @@ def __init__(self, model: str = "embed-english-v3.0"):
self.model = model
self.co = cohere.Client(api_key)

def __call__(self, sentences: List[str]) -> Tensor:
def __call__(self, sentences: list[str]) -> Tensor:
from cohere import EmbedResponse

response: EmbedResponse = self.co.embed(model=self.model,
Expand All @@ -106,13 +105,13 @@ def __init__(self, model: str = "voyage-01"):
# Please run `pip install voyageai` to install the package
self.model = model

def __call__(self, sentences: List[str]) -> Tensor:
def __call__(self, sentences: list[str]) -> Tensor:
import voyageai # noqa

voyageai.api_key = api_key
from voyageai import get_embeddings

items: List[List[float]] = get_embeddings(sentences, model=self.model)
items: list[list[float]] = get_embeddings(sentences, model=self.model)
assert len(items) == len(sentences)
embeddings = [torch.FloatTensor(item).view(1, -1) for item in items]
return torch.cat(embeddings, dim=0)
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import argparse
import math
import os.path as osp
from typing import Any, Dict, List
from typing import Any

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -157,8 +157,8 @@ def __init__(
out_channels: int,
num_layers: int,
# kwargs for feature encoder
col_stats: Dict[str, Dict[StatType, Any]],
col_names_dict: Dict[torch_frame.stype, List[str]],
col_stats: dict[str, dict[StatType, Any]],
col_names_dict: dict[torch_frame.stype, list[str]],
):
super().__init__()
# Specify what feature encoder to use for each stype.
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors=[
]
description="Tabular Deep Learning Library for PyTorch"
readme="README.md"
requires-python=">=3.8"
requires-python=">=3.9"
keywords=[
"deep-learning",
"pytorch",
Expand All @@ -21,7 +21,6 @@ classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down Expand Up @@ -83,7 +82,7 @@ ignore = [
src = ["torch_frame"]
line-length = 80
indent-width = 4
target-version = "py38"
target-version = "py39"

# [tool.ruff.per-files-ignores]

Expand Down
2 changes: 1 addition & 1 deletion readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.9"

python:
install:
Expand Down
12 changes: 6 additions & 6 deletions test/data/test_multi_embedding_tensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import List, Optional, Tuple, Union
from typing import Optional, Union

import pytest
import torch
Expand All @@ -9,7 +9,7 @@


def assert_equal(
tensor_list: List[torch.Tensor],
tensor_list: list[torch.Tensor],
met: MultiEmbeddingTensor,
) -> None:
assert len(tensor_list) == met.num_cols
Expand All @@ -22,9 +22,9 @@ def assert_equal(


def row_select(
tensor_list: List[torch.Tensor],
index: Union[List[int], slice],
) -> List[torch.Tensor]:
tensor_list: list[torch.Tensor],
index: Union[list[int], slice],
) -> list[torch.Tensor]:
"""Selects rows from a list of column tensors.
Args:
Expand All @@ -45,7 +45,7 @@ def get_fake_multi_embedding_tensor(
num_cols: int,
embedding_dim: Optional[int] = None,
device: Optional[torch.device] = None,
) -> Tuple[MultiEmbeddingTensor, List[torch.Tensor]]:
) -> tuple[MultiEmbeddingTensor, list[torch.Tensor]]:
tensor_list = []
for _ in range(num_cols):
embedding_dim = embedding_dim or random.randint(1, 5)
Expand Down
10 changes: 5 additions & 5 deletions test/data/test_multi_nested_tensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import List, Union
from typing import Union

import pytest
import torch
Expand All @@ -9,7 +9,7 @@
from torch_frame.testing import withCUDA


def assert_equal(tensor_mat: List[List[Tensor]],
def assert_equal(tensor_mat: list[list[Tensor]],
multi_nested_tensor: MultiNestedTensor):
assert len(tensor_mat) == multi_nested_tensor.shape[0]
assert len(tensor_mat[0]) == multi_nested_tensor.shape[1]
Expand All @@ -20,9 +20,9 @@ def assert_equal(tensor_mat: List[List[Tensor]],


def column_select(
tensor_mat: List[List[Tensor]],
index: Union[List[int], slice],
) -> List[List[Tensor]]:
tensor_mat: list[list[Tensor]],
index: Union[list[int], slice],
) -> list[list[Tensor]]:
new_tensor_mat = []
for tensor_vec in tensor_mat:
if isinstance(index, slice):
Expand Down
6 changes: 2 additions & 4 deletions test/nn/test_simple_basecls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List, Tuple

import torch
from torch import Tensor

Expand All @@ -15,7 +13,7 @@ def __init__(
self,
out_channels: int,
num_numerical: int,
num_categories: List[int],
num_categories: list[int],
):
super().__init__()

Expand All @@ -31,7 +29,7 @@ def __init__(
for num_category in num_categories
])

def forward(self, tf: TensorFrame) -> Tuple[Tensor, List[str]]:
def forward(self, tf: TensorFrame) -> tuple[Tensor, list[str]]:
xs = []
for i, lin in enumerate(self.lins):
xs.append(lin(tf.feat_dict[torch_frame.numerical][:, i:i + 1]))
Expand Down
3 changes: 2 additions & 1 deletion torch_frame/data/mapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any, Callable, Iterable, Mapping
from collections.abc import Iterable, Mapping
from typing import Any, Callable

import numpy as np
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion torch_frame/data/multi_embedding_tensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Sequence
from collections.abc import Sequence

import torch
from torch import Tensor
Expand Down
3 changes: 2 additions & 1 deletion torch_frame/data/multi_nested_tensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Sequence, cast
from collections.abc import Sequence
from typing import cast

import torch
from torch import Tensor
Expand Down
3 changes: 2 additions & 1 deletion torch_frame/data/multi_tensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import copy
from typing import Any, Callable, Sequence, TypeVar
from collections.abc import Sequence
from typing import Any, Callable, TypeVar

import torch
from torch import Tensor
Expand Down
3 changes: 1 addition & 2 deletions torch_frame/nn/encoder/encoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import ABC, abstractmethod
from typing import List, Tuple

from torch import Tensor
from torch.nn import Module
Expand All @@ -16,7 +15,7 @@ class FeatureEncoder(Module, ABC):
value handling.
"""
@abstractmethod
def forward(self, tf: TensorFrame) -> Tuple[Tensor, List[str]]:
def forward(self, tf: TensorFrame) -> tuple[Tensor, list[str]]:
r"""Encode :class:`TensorFrame` object into a tuple
:obj:`(x, col_names)`.
Expand Down
11 changes: 6 additions & 5 deletions torch_frame/typing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Mapping
from enum import Enum
from typing import Dict, List, Mapping, Union
from typing import Union

import pandas as pd
import torch
Expand Down Expand Up @@ -109,14 +110,14 @@ def is_timestamp_strategy(self) -> bool:
Series = pd.Series
DataFrame = pd.DataFrame

IndexSelectType = Union[int, List[int], range, slice, Tensor]
ColumnSelectType = Union[str, List[str]]
IndexSelectType = Union[int, list[int], range, slice, Tensor]
ColumnSelectType = Union[str, list[str]]
TextTokenizationMapping = Mapping[str, Tensor]
TextTokenizationOutputs = Union[List[TextTokenizationMapping],
TextTokenizationOutputs = Union[list[TextTokenizationMapping],
TextTokenizationMapping]
TensorData = Union[
Tensor,
MultiNestedTensor,
MultiEmbeddingTensor,
Dict[str, MultiNestedTensor],
dict[str, MultiNestedTensor],
]
Loading

0 comments on commit d698f26

Please sign in to comment.