Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT] python 3.12 compatibility - replace distutils calls with equivalent functionality #5376

Merged
merged 9 commits into from Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion sktime/datasets/_readers_writers/tsf.py
Expand Up @@ -5,12 +5,12 @@
__all__ = ["load_tsf_to_dataframe"]

from datetime import datetime
from distutils.util import strtobool
from typing import Dict

import pandas as pd

from sktime.datatypes import MTYPE_LIST_HIERARCHICAL, convert
from sktime.utils.strtobool import strtobool


def _convert_tsf_to_hierarchical(
Expand Down
8 changes: 4 additions & 4 deletions sktime/transformations/series/fourier.py
Expand Up @@ -4,7 +4,6 @@
__author__ = ["ltsaprounis", "blazingbhavneek"]

import warnings
from distutils.log import warn
from typing import List, Optional

import numpy as np
Expand Down Expand Up @@ -181,9 +180,10 @@ def _fit(self, X, y=None):
if self.freq_ is None:
ValueError("X has no known frequency and none is supplied")
if self.freq_ == time_index.freq and self.freq_ != self.freq:
warn(
f"Using frequency from index: {time_index.freq}, which \
does not match the frequency given:{self.freq}."
warnings.warn(
f"Using frequency from index: {time_index.freq}, which"
f"does not match the frequency given:{self.freq}.",
stacklevel=2,
)
time_index = time_index.to_period(self.freq_)
# this is used to make sure that time t is calculated with reference to
Expand Down
35 changes: 35 additions & 0 deletions sktime/utils/strtobool.py
@@ -0,0 +1,35 @@
"""String-to-int coercion utility strtobool formerly in deprecated distutils."""


# distutils has been removed in Python 3.12,
# but this function is still used in parts of the sktime codebase
def strtobool(val):
fkiraly marked this conversation as resolved.
Show resolved Hide resolved
"""Convert a string representation of truth to int, true (1) or false (0).

True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.

Parameters
----------
val : str
A string representation of truth.

Returns
-------
int, 0 or 1
val coerced to int
1 if val is a true value, 0 if val is a false value (see above)

Raises
------
ValueError
If val is anything other than the strings above.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return 1
elif val in ("n", "no", "f", "false", "off", "0"):
return 0
else:
raise ValueError(f"invalid truth value {val!r}")
fkiraly marked this conversation as resolved.
Show resolved Hide resolved