Skip to content

Commit

Permalink
Remove code for Python 3.7 compatibility. Update mypi to use 3.8
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Shinnar <[email protected]>
  • Loading branch information
shinnar committed Jan 31, 2024
1 parent 846dfc0 commit 1c37efc
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 63 deletions.
8 changes: 1 addition & 7 deletions lale/datasets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from typing import Any, Tuple, overload
from typing import Any, Literal, Tuple, overload

import numpy as np
import pandas as pd
from sklearn.utils import Bunch

from lale.datasets.data_schemas import add_table_name, get_table_name

if sys.version_info >= (3, 8):
from typing import Literal # raises a mypy error for <3.8
else:
from typing_extensions import Literal

try:
from pyspark.sql import SparkSession

Expand Down
3 changes: 1 addition & 2 deletions lale/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import typing
from copy import deepcopy
from io import StringIO
from typing import Any, Dict, Optional, Union, overload
from typing import Any, Dict, Literal, Optional, Union, overload

import astunparse
from typing_extensions import Literal

AstLits = (ast.Num, ast.Str, ast.List, ast.Tuple, ast.Set, ast.Dict, ast.Constant)
AstLit = Union[ast.Num, ast.Str, ast.List, ast.Tuple, ast.Set, ast.Dict, ast.Constant]
Expand Down
7 changes: 1 addition & 6 deletions lale/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import copy
import importlib
import logging
import sys
import time
import traceback
from importlib import util
Expand All @@ -26,6 +25,7 @@
Dict,
Iterable,
List,
Literal,
Mapping,
Optional,
Set,
Expand All @@ -46,11 +46,6 @@

import lale.datasets.data_schemas

if sys.version_info >= (3, 8):
from typing import Literal # raises a mypy error for <3.8
else:
from typing_extensions import Literal

try:
import torch

Expand Down
9 changes: 1 addition & 8 deletions lale/lib/aif360/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import functools
import logging
import sys
from typing import List, Optional, Tuple, Union, cast
from typing import List, Literal, Optional, Tuple, Union, cast

import aif360.algorithms.postprocessing
import aif360.datasets
Expand All @@ -38,12 +37,6 @@
from lale.operators import TrainablePipeline, TrainedOperator
from lale.type_checking import JSON_TYPE, validate_schema_directly

if sys.version_info >= (3, 8):
from typing import Literal # raises a mypy error for <3.8
else:
from typing_extensions import Literal


logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)

Expand Down
4 changes: 2 additions & 2 deletions lale/lib/rasl/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Iterable, Tuple, Union, cast, overload
from typing import Iterable, Literal, Tuple, Union, cast, overload

import pandas as pd
import sklearn.model_selection
import sklearn.tree
from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

import lale.helpers
from lale.datasets import pandas2spark
Expand Down
3 changes: 1 addition & 2 deletions lale/lib/rasl/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# limitations under the License.

import datetime
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar
from typing import Any, Callable, Dict, Generic, List, Optional, Protocol, TypeVar

import numpy as np
from typing_extensions import Protocol

from lale.helpers import _is_pandas_df, _is_spark_df

Expand Down
4 changes: 2 additions & 2 deletions lale/lib/rasl/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import functools
from abc import abstractmethod
from typing import Dict, Iterable, Optional, Tuple, TypeVar, Union, cast
from typing import Dict, Iterable, Optional, Protocol, Tuple, TypeVar, Union, cast

import numpy as np
import pandas as pd
from typing_extensions import Protocol, TypeAlias
from typing_extensions import TypeAlias

from lale.expressions import astype, count, it
from lale.expressions import sum as lale_sum
Expand Down
4 changes: 1 addition & 3 deletions lale/lib/rasl/monoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
# limitations under the License.

from abc import ABC, abstractmethod
from typing import Any, Generic, Optional, TypeVar

from typing_extensions import Protocol, runtime_checkable
from typing import Any, Generic, Optional, Protocol, TypeVar, runtime_checkable

_InputType_contra = TypeVar("_InputType_contra", contravariant=True)
_OutputType_co = TypeVar("_OutputType_co", covariant=True)
Expand Down
3 changes: 1 addition & 2 deletions lale/lib/rasl/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional
from typing import Any, List, Optional, Protocol

import numpy as np
from typing_extensions import Protocol

import lale.datasets.data_schemas
import lale.docstrings
Expand Down
3 changes: 1 addition & 2 deletions lale/lib/rasl/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Tuple, TypeVar
from typing import Any, Protocol, Tuple, TypeVar

import numpy as np
from scipy import special
from typing_extensions import Protocol

from lale.expressions import count as agg_count
from lale.expressions import it
Expand Down
8 changes: 1 addition & 7 deletions lale/operator_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@

import inspect
import logging
import sys
from typing import List, Optional, Set
from typing import Container, List, Optional, Set

from lale.operators import Operator, clone_op, get_op_from_lale_lib

if sys.version_info < (3, 9):
from typing import Container # raises a mypy error for <3.8
else:
from collections.abc import Container

logger = logging.getLogger(__name__)


Expand Down
7 changes: 1 addition & 6 deletions lale/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
import itertools
import logging
import os
import sys
import warnings
from abc import abstractmethod
from types import MappingProxyType
Expand All @@ -164,6 +163,7 @@
Generic,
Iterable,
List,
Literal,
Mapping,
Optional,
Set,
Expand Down Expand Up @@ -230,11 +230,6 @@

sklearn_version = version.parse(getattr(sklearn, "__version__"))

if sys.version_info >= (3, 8):
from typing import Literal # raises a mypy error for <3.8
else:
from typing_extensions import Literal

try:
from sklearn.pipeline import ( # pylint:disable=ungrouped-imports
if_delegate_has_method,
Expand Down
14 changes: 1 addition & 13 deletions lale/util/VisitorMeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# A shim for compatibility across 3.7.
# pre 3.7, we need to inherit from the GenericMeta class (which inherits from ABCmeta)
# to use Generic (which we want to do)
# post 3.7, GenericMeta no longer exists
import sys
from abc import ABCMeta


Expand Down Expand Up @@ -53,14 +48,7 @@ def __init__(cls, *args, **kwargs):
setattr(cls, "_accept", ll["_accept"])


if sys.version_info < (3, 7, 0):
from typing import GenericMeta # type: ignore
else:
global GenericMeta # pylint:disable=global-at-module-level
GenericMeta = ABCMeta # type: ignore


class AbstractVisitorMeta(VisitorMeta, GenericMeta):
class AbstractVisitorMeta(VisitorMeta, ABCMeta):
"""This meta class adds an _accept method that calls visitCLASSNAME on the visitor.
It does not currently support inheritance: you need to define the visitC method for subclasses
explicitly.
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.7
python_version = 3.8
ignore_missing_imports = True

[mypy-pandas]
Expand Down

0 comments on commit 1c37efc

Please sign in to comment.