Skip to content

Commit

Permalink
Add support to python 3.11 (#1326)
Browse files Browse the repository at this point in the history
* Add support to python 3.11

* Fix workflow python version comparison

* Ray is not supported in python 3.11

* Fix test_numpy
  • Loading branch information
thinkall authored Jul 31, 2024
1 parent 15fda22 commit a68d073
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -59,22 +59,22 @@ jobs:
run: |
pip install pyspark==3.2.3
pip list | grep "pyspark"
- name: If linux, install ray 2
if: matrix.os == 'ubuntu-latest'
- name: If linux and python<3.11, install ray 2
if: matrix.os == 'ubuntu-latest' && matrix.python-version != '3.11'
run: |
pip install "ray[tune]<2.5.0"
- name: If mac, install ray and xgboost 1
if: matrix.os == 'macOS-latest'
- name: If mac and python 3.10, install ray and xgboost 1
if: matrix.os == 'macOS-latest' && matrix.python-version == '3.10'
run: |
pip install -e .[ray]
# use macOS to test xgboost 1, but macOS also supports xgboost 2
pip install "xgboost<2"
- name: If linux, install prophet on python < 3.9
if: matrix.os == 'ubuntu-latest' && matrix.python-version < '3.9'
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8'
run: |
pip install -e .[forecast]
- name: Install vw on python < 3.10
if: matrix.python-version != '3.10'
if: matrix.python-version == '3.8' || matrix.python-version == '3.9'
run: |
pip install -e .[vw]
- name: Uninstall pyspark on (python 3.9) or windows
Expand Down
12 changes: 7 additions & 5 deletions flaml/automl/time_series/ts_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class PD:
DataFrame = Series = None


# dataclass will remove empty default value even with field(default_factory=lambda: [])
# Change into default=None to place the attr
@dataclass
class TimeSeriesDataset:
train_data: pd.DataFrame
Expand All @@ -34,10 +36,10 @@ class TimeSeriesDataset:
target_names: List[str]
frequency: str
test_data: pd.DataFrame
time_varying_known_categoricals: List[str] = field(default_factory=lambda: [])
time_varying_known_reals: List[str] = field(default_factory=lambda: [])
time_varying_unknown_categoricals: List[str] = field(default_factory=lambda: [])
time_varying_unknown_reals: List[str] = field(default_factory=lambda: [])
time_varying_known_categoricals: List[str] = field(default=None)
time_varying_known_reals: List[str] = field(default=None)
time_varying_unknown_categoricals: List[str] = field(default=None)
time_varying_unknown_reals: List[str] = field(default=None)

def __init__(
self,
Expand Down Expand Up @@ -403,7 +405,7 @@ def fit(self, X: Union[DataFrame, np.array], y):
self.cat_columns.append(column)
elif X[column].nunique(dropna=True) < 2:
self.drop_columns.append(column)
elif X[column].dtype.name == "datetime64[ns]":
elif X[column].dtype.name in ["datetime64[ns]", "datetime64[s]"]:
pass # these will be processed at model level,
# so they can also be done in the predict method
else:
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"xgboost>=0.90,<2.0.0",
"scipy>=1.4.1",
"pandas>=1.1.4",
"scikit-learn>=0.24",
"scikit-learn>=1.0.0",
],
"notebook": [
"jupyter",
Expand All @@ -51,11 +51,12 @@
"joblib<=1.3.2",
],
"test": [
"jupyter",
"lightgbm>=2.3.1",
"xgboost>=0.90,<2.0.0",
"scipy>=1.4.1",
"pandas>=1.1.4",
"scikit-learn>=0.24",
"scikit-learn>=1.0.0",
"thop",
"pytest>=6.1.1",
"coverage>=5.3",
Expand Down Expand Up @@ -92,7 +93,10 @@
"sympy",
"wolframalpha",
],
"catboost": ["catboost>=0.26"],
"catboost": [
"catboost>=0.26,<1.2; python_version<'3.11'",
"catboost>=0.26,<=1.2.5; python_version>='3.11'",
],
"blendsearch": [
"optuna>=2.8.0,<=3.6.1",
"packaging",
Expand Down
10 changes: 8 additions & 2 deletions test/automl/test_forecast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime
import sys

import numpy as np
import pandas as pd
import pytest

from flaml import AutoML
from flaml.automl.task.time_series_task import TimeSeriesTask
Expand Down Expand Up @@ -495,6 +497,10 @@ def get_stalliion_data():
return data, special_days


@pytest.mark.skipif(
"3.11" in sys.version,
reason="do not run on py 3.11",
)
def test_forecast_panel(budget=5):
data, special_days = get_stalliion_data()
time_horizon = 6 # predict six months
Expand Down Expand Up @@ -666,7 +672,7 @@ def split_by_date(df: pd.DataFrame, dt: datetime.date):
# test_forecast_automl(60)
# test_multivariate_forecast_num(5)
# test_multivariate_forecast_cat(5)
# test_numpy()
test_numpy()
# test_forecast_classification(5)
test_forecast_panel(5)
# test_forecast_panel(5)
# test_cv_step()
9 changes: 8 additions & 1 deletion test/tune/test_lexiflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision

try:
import torchvision
except ImportError:
torchvision = None

from flaml import tune

Expand Down Expand Up @@ -35,6 +39,9 @@ def _BraninCurrin(config):


def test_lexiflow():
if torchvision is None:
return False

train_dataset = torchvision.datasets.FashionMNIST(
"test/data",
train=True,
Expand Down

0 comments on commit a68d073

Please sign in to comment.