Skip to content

Commit

Permalink
Merge pull request #422 from sebp/py-3-12
Browse files Browse the repository at this point in the history
Add support for Python 3.12
  • Loading branch information
sebp authored Dec 21, 2023
2 parents c5f4a0e + d5a6f5c commit ed70f6b
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
fail-fast: false
matrix:
config:
- py38_pandas11_numpy121_sklearn13
- py39_pandas14_numpy122_sklearn13
- py310_pandas15_numpy124_sklearn13
- py311_pandas20_numpy124_sklearn13
- py312_pandas21_numpy126_sklearn13
runner:
- ubuntu-latest
- macos-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheels-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-2019, macos-11]
python: [38, 39, 310, 311]
python: [38, 39, 310, 311, 312]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ image: Visual Studio 2019
environment:
# see https://www.appveyor.com/docs/build-environment/#python
matrix:
- TARGET_ARCH: "x64"
CONDA_PY: "38"
- TARGET_ARCH: "x64"
CONDA_PY: "39"
- TARGET_ARCH: "x64"
CONDA_PY: "310"
- TARGET_ARCH: "x64"
CONDA_PY: "311"
- TARGET_ARCH: "x64"
CONDA_PY: "312"


# We always use a 64-bit machine.
Expand Down
4 changes: 4 additions & 0 deletions ci/appveyor/py312.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$env:CI_PYTHON_VERSION="3.12.*"
$env:CI_PANDAS_VERSION="2.1.*"
$env:CI_NUMPY_VERSION="1.26.*"
$env:CI_SKLEARN_VERSION="1.3.*"
4 changes: 0 additions & 4 deletions ci/appveyor/py38.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion ci/deps/py311_pandas20_numpy124_sklearn13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export CI_PYTHON_VERSION='3.11.*'
export CI_PANDAS_VERSION='2.0.*'
export CI_NUMPY_VERSION='1.24.*'
export CI_SKLEARN_VERSION='1.3.*'
export CI_NO_SLOW=false
export CI_NO_SLOW=true
6 changes: 6 additions & 0 deletions ci/deps/py312_pandas21_numpy126_sklearn13.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# shellcheck shell=sh
export CI_PYTHON_VERSION='3.12.*'
export CI_PANDAS_VERSION='2.1.*'
export CI_NUMPY_VERSION='1.26.*'
export CI_SKLEARN_VERSION='1.3.*'
export CI_NO_SLOW=false
6 changes: 0 additions & 6 deletions ci/deps/py38_pandas11_numpy121_sklearn13.sh

This file was deleted.

2 changes: 1 addition & 1 deletion ci/deps/py39_pandas14_numpy122_sklearn13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export CI_PYTHON_VERSION='3.9.*'
export CI_PANDAS_VERSION='1.4.*'
export CI_NUMPY_VERSION='1.22.*'
export CI_SKLEARN_VERSION='1.3.*'
export CI_NO_SLOW=true
export CI_NO_SLOW=false
7 changes: 2 additions & 5 deletions ci/deps/requirements.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ dependencies:
- coverage
- cython>=0.29
- ecos
- ipykernel
- ipython!=8.7.0
- joblib
- matplotlib>=3.6.2,<3.7
- nbformat
- matplotlib>=3.8.0,<3.9
- numexpr
- numpy={CI_NUMPY_VERSION}
- osqp!=0.6.0,!=0.6.1
Expand All @@ -29,4 +26,4 @@ dependencies:
- build
- importlib-resources>=1.3
- nbval>=0.10.0
- tomli
- tomli
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ requires = [
"numpy==1.19.3; python_version=='3.9' and platform_machine != 'arm64'",
"numpy==1.21.6; python_version=='3.10'",
"numpy==1.23.2; python_version=='3.11'",
"numpy; python_version>'3.11'",
"numpy==1.26.1; python_version=='3.12'",
"numpy; python_version>'3.12'",

# scikit-learn requirements
"scikit-learn~=1.3.0; python_version<='3.9'",
"scikit-learn~=1.3.0; python_version=='3.10'",
"scikit-learn~=1.3.0; python_version=='3.11'",
"scikit-learn; python_version>'3.11'",
"scikit-learn~=1.3.0; python_version=='3.12'",
"scikit-learn; python_version>'3.12'",
]
build-backend = "setuptools.build_meta"

Expand Down Expand Up @@ -140,9 +142,11 @@ filterwarnings = [
"ignore:distutils Version classes are deprecated.*:DeprecationWarning",
"ignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning",
# added with pandas 2.1
"ignore:is_categorical_dtype is deprecated and will be removed in a future version:FutureWarning",
# added with pandas 2.1
"ignore:DataFrame.applymap has been deprecated:FutureWarning",
# deprecated since Python 3.12
"ignore:datetime\\.datetime\\.utcfromtimestamp\\(\\) is deprecated and scheduled for removal in a future version.*:DeprecationWarning",
"ignore:ast\\.Num is deprecated and will be removed in Python 3\\.14.*:DeprecationWarning",
"ignore:Attribute n is deprecated and will be removed in Python 3\\.14.*:DeprecationWarning",
]

[tool.coverage.run]
Expand Down
10 changes: 5 additions & 5 deletions sksurv/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_categorical_dtype
from pandas.api.types import CategoricalDtype, is_object_dtype

__all__ = ["categorical_to_numeric", "encode_categorical", "standardize"]

Expand Down Expand Up @@ -125,12 +125,12 @@ def encode_categorical(table, columns=None, **kwargs):
Numeric columns in the input table remain unchanged.
"""
if isinstance(table, pd.Series):
if not is_categorical_dtype(table.dtype) and not table.dtype.char == "O":
if not isinstance(table.dtype, CategoricalDtype) and not is_object_dtype(table.dtype):
raise TypeError(f"series must be of categorical dtype, but was {table.dtype}")
return _encode_categorical_series(table, **kwargs)

def _is_categorical_or_object(series):
return is_categorical_dtype(series.dtype) or series.dtype.char == "O"
return isinstance(series.dtype, CategoricalDtype) or is_object_dtype(series.dtype)

if columns is None:
# for columns containing categories
Expand Down Expand Up @@ -191,9 +191,9 @@ def categorical_to_numeric(table):
"""

def transform(column):
if is_categorical_dtype(column.dtype):
if isinstance(column.dtype, CategoricalDtype):
return column.cat.codes
if column.dtype.char == "O":
if is_object_dtype(column.dtype):
try:
nc = column.astype(np.int64)
except ValueError:
Expand Down
4 changes: 2 additions & 2 deletions sksurv/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_categorical_dtype
from pandas.api.types import CategoricalDtype

from ..column import categorical_to_numeric, standardize
from ..io import loadarff
Expand Down Expand Up @@ -102,7 +102,7 @@ def get_x_y(data_frame, attr_labels, pos_label=None, survival=True):
def _loadarff_with_index(filename):
dataset = loadarff(filename)
if "index" in dataset.columns:
if is_categorical_dtype(dataset["index"].dtype):
if isinstance(dataset["index"].dtype, CategoricalDtype):
# concatenating categorical index may raise TypeError
# see https://github.com/pandas-dev/pandas/issues/14586
dataset["index"] = dataset["index"].astype(object)
Expand Down
6 changes: 3 additions & 3 deletions sksurv/io/arffwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np
import pandas as pd
from pandas.api.types import is_categorical_dtype, is_object_dtype
from pandas.api.types import CategoricalDtype, is_object_dtype

_ILLEGAL_CHARACTER_PAT = re.compile(r"[^-_=\w\d\(\)<>\.]")

Expand Down Expand Up @@ -70,7 +70,7 @@ def _write_header(data, fp, relation_name, index):
name = attribute_names[column]
fp.write(f"@attribute {name}\t")

if is_categorical_dtype(series) or is_object_dtype(series):
if isinstance(series.dtype, CategoricalDtype) or is_object_dtype(series):
_write_attribute_categorical(series, fp)
elif np.issubdtype(series.dtype, np.floating):
fp.write("real")
Expand Down Expand Up @@ -114,7 +114,7 @@ def _check_str_value(x):

def _write_attribute_categorical(series, fp):
"""Write categories of a categorical/nominal attribute"""
if is_categorical_dtype(series.dtype):
if isinstance(series.dtype, CategoricalDtype):
categories = series.cat.categories
string_values = _check_str_array(categories)
else:
Expand Down
4 changes: 2 additions & 2 deletions sksurv/kernels/clinical.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
import pandas as pd
from pandas.api.types import is_categorical_dtype, is_numeric_dtype
from pandas.api.types import CategoricalDtype, is_numeric_dtype
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.utils.validation import check_is_fitted

Expand Down Expand Up @@ -178,7 +178,7 @@ def _prepare_by_column_dtype(self, X):

for i, dt in enumerate(X.dtypes):
col = X.iloc[:, i]
if is_categorical_dtype(dt):
if isinstance(dt, CategoricalDtype):
if col.cat.ordered:
numeric_ranges.append(col.cat.codes.max() - col.cat.codes.min())
numeric_columns.append(i)
Expand Down
4 changes: 2 additions & 2 deletions sksurv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
import pandas as pd
from pandas.api.types import is_categorical_dtype
from pandas.api.types import CategoricalDtype
from sklearn.utils import check_array, check_consistent_length

__all__ = ["check_array_survival", "check_y_survival", "safe_concat", "Surv"]
Expand Down Expand Up @@ -251,7 +251,7 @@ def safe_concat(objs, *args, **kwargs):
categories = {}
for df in objs:
if isinstance(df, pd.Series):
if is_categorical_dtype(df.dtype):
if isinstance(df.dtype, CategoricalDtype):
categories[df.name] = {"categories": df.cat.categories, "ordered": df.cat.ordered}
else:
dfc = df.select_dtypes(include=["category"])
Expand Down

0 comments on commit ed70f6b

Please sign in to comment.