Skip to content

Commit

Permalink
Drop Python 3.8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan committed Aug 5, 2024
1 parent 3869eee commit c29f303
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
test:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

runs-on: ubuntu-latest

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __pycache__/
.mypy_cache/
.pytest_cache/
.ruff_cache/
.coverage
.coverage
dist/
2 changes: 1 addition & 1 deletion docs/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pip install sknnr --pre

## Dependencies

- Python >= 3.8
- Python >= 3.9
- scikit-learn >= 1.2
- numpy
- scipy
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
description = "Scikit-learn estimators for kNN regression methods"
readme = "README.md"
license = ""
requires-python = ">=3.8"
requires-python = ">=3.9"
authors = [
{ name = "Matt Gregory", email = "matt.gregory@oregonstate.edu" },
{ name = "Aaron Zuspan", email = "aaron.zuspan@oregonstate.edu" },
Expand Down Expand Up @@ -52,7 +52,6 @@ markers = [
]

[tool.ruff]
target-version = "py38"
fix = true
show-fixes = true

Expand Down
17 changes: 2 additions & 15 deletions src/sknnr/datasets/_base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

import csv
import sys
import types
from dataclasses import dataclass
from importlib import resources
from typing import IO, TYPE_CHECKING
from typing import TYPE_CHECKING

import numpy as np
from numpy.typing import NDArray
Expand Down Expand Up @@ -55,18 +54,6 @@ def _dataset_as_frame(dataset: Dataset) -> Dataset:
)


def _open_text(module_name: str | types.ModuleType, file_name: str) -> IO[str]:
"""Open a file as text.
This is a compatibility port for importlib.resources.open_text, which is deprecated
in Python>=3.9. This function will be removed when support for Python 3.8 is
dropped.
"""
if sys.version_info >= (3, 9):
return resources.files(module_name).joinpath(file_name).open("r")
return resources.open_text(module_name, file_name)


def load_csv_data(
file_name: str, *, module_name: str | types.ModuleType = DATA_MODULE
) -> tuple[NDArray[np.int64], NDArray[np.float64], NDArray[np.str_]]:
Expand All @@ -93,7 +80,7 @@ def load_csv_data(
The CSV must be formatted with plot IDs in the first column and data values in the
remaining columns. The first row must contain the column names.
"""
with _open_text(module_name, file_name) as csv_file:
with resources.files(module_name).joinpath(file_name).open("r") as csv_file:
data_file = csv.reader(csv_file)
headers = next(data_file)
rows = list(iter(data_file))
Expand Down
4 changes: 2 additions & 2 deletions tests/datasets.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

from dataclasses import dataclass
from importlib import resources

import numpy as np
import pandas as pd
from numpy.typing import NDArray
from sklearn.model_selection import train_test_split

from sknnr.datasets import load_moscow_stjoes
from sknnr.datasets._base import _open_text

TEST_DATA_MODULE = "tests.data"

Expand Down Expand Up @@ -90,5 +90,5 @@ def load_moscow_stjoes_results(

def _load_test_data(filename: str) -> pd.DataFrame:
"""Load a test dataset from the tests/data directory."""
with _open_text(TEST_DATA_MODULE, filename) as fh:
with resources.files(TEST_DATA_MODULE).joinpath(filename).open("r") as fh:
return pd.read_csv(fh)
5 changes: 3 additions & 2 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def test_load_dataset_as_xy_as_frame(configuration: DatasetConfiguration):
)
def test_asframe_raises_without_pandas(configuration: DatasetConfiguration):
"""Test that as_frame=True raises a helpful error if pandas is not installed."""
with mock.patch.dict(sys.modules, {"pandas": None}), pytest.raises(
ImportError, match="pip install pandas"
with (
mock.patch.dict(sys.modules, {"pandas": None}),
pytest.raises(ImportError, match="pip install pandas"),
):
configuration.load_function(as_frame=True)

Expand Down

0 comments on commit c29f303

Please sign in to comment.