From 3cbb30009d5c79f32ff1b4579b2bad230850c2b9 Mon Sep 17 00:00:00 2001 From: Ian Lumsden Date: Thu, 14 Nov 2024 15:44:49 -0500 Subject: [PATCH] Tweaks imports of Callable and Iterable based on Python version --- hatchet/graph.py | 7 ++++++- hatchet/graphframe.py | 6 +++++- hatchet/node.py | 7 ++++++- hatchet/query/compat.py | 7 ++++++- hatchet/query/object_dialect.py | 6 +++++- hatchet/query/query.py | 7 ++++++- hatchet/query/string_dialect.py | 6 +++++- hatchet/readers/caliper_native_reader.py | 7 ++++++- hatchet/readers/caliper_reader.py | 6 +++++- hatchet/readers/literal_reader.py | 7 ++++++- hatchet/readers/tau_reader.py | 8 +++++++- 11 files changed, 63 insertions(+), 11 deletions(-) diff --git a/hatchet/graph.py b/hatchet/graph.py index 91524d29..5555ccdc 100644 --- a/hatchet/graph.py +++ b/hatchet/graph.py @@ -3,10 +3,15 @@ # # SPDX-License-Identifier: MIT +import sys from collections import defaultdict -from collections.abc import Iterable from typing import Any, Dict, List, Optional, Set, Tuple, Union +if sys.version_info >= (3, 9): + from collections.abc import Iterable +else: + from typing import Iterable + from .node import Node, traversal_order, node_traversal_order diff --git a/hatchet/graphframe.py b/hatchet/graphframe.py index 5e1ff5e3..ffddcc8f 100644 --- a/hatchet/graphframe.py +++ b/hatchet/graphframe.py @@ -8,10 +8,14 @@ import sys import traceback from collections import defaultdict -from collections.abc import Callable, Iterable from typing import Any, Dict, List, Optional, Set, Tuple, Union, cast from io import TextIOWrapper +if sys.version_info >= (3, 9): + from collections.abc import Callable, Iterable +else: + from typing import Callable, Iterable + import multiprocess as mp import numpy as np import pandas as pd diff --git a/hatchet/node.py b/hatchet/node.py index f1205642..7c76c3c9 100644 --- a/hatchet/node.py +++ b/hatchet/node.py @@ -3,9 +3,14 @@ # # SPDX-License-Identifier: MIT +import sys from functools import total_ordering from typing import Any, Dict, List, Optional, Set, Tuple, Union -from collections.abc import Iterable + +if sys.version_info >= (3, 9): + from collections.abc import Iterable +else: + from typing import Iterable from .frame import Frame diff --git a/hatchet/query/compat.py b/hatchet/query/compat.py index a2a96d6d..8408d20b 100644 --- a/hatchet/query/compat.py +++ b/hatchet/query/compat.py @@ -7,9 +7,14 @@ import sys import warnings -from collections.abc import Callable from typing import List, Optional, Union, cast, TYPE_CHECKING +if sys.version_info >= (3, 9): + from collections.abc import Callable +else: + from typing import Callable + + from ..node import Node from .query import Query from .compound import ( diff --git a/hatchet/query/object_dialect.py b/hatchet/query/object_dialect.py index cd0ed641..9e5e120d 100644 --- a/hatchet/query/object_dialect.py +++ b/hatchet/query/object_dialect.py @@ -13,7 +13,11 @@ import re import sys from typing import Dict, List, Tuple, Union -from collections.abc import Callable, Iterable + +if sys.version_info >= (3, 9): + from collections.abc import Callable, Iterable +else: + from typing import Callable, Iterable from .errors import InvalidQueryPath, InvalidQueryFilter, MultiIndexModeMismatch from ..node import Node diff --git a/hatchet/query/query.py b/hatchet/query/query.py index d3be624e..3eb8e2ea 100644 --- a/hatchet/query/query.py +++ b/hatchet/query/query.py @@ -3,8 +3,13 @@ # # SPDX-License-Identifier: MIT +import sys from typing import List, Tuple, Union -from collections.abc import Callable, Iterator + +if sys.version_info >= (3, 9): + from collections.abc import Callable, Iterator +else: + from typing import Callable, Iterator from .errors import InvalidQueryPath diff --git a/hatchet/query/string_dialect.py b/hatchet/query/string_dialect.py index 9a76865c..ec717127 100644 --- a/hatchet/query/string_dialect.py +++ b/hatchet/query/string_dialect.py @@ -5,7 +5,6 @@ from numbers import Real import sys -from collections.abc import Callable from typing import Any, Dict, Optional, List, Union import pandas as pd # noqa: F401 from pandas.api.types import is_numeric_dtype, is_string_dtype # noqa: F401 @@ -14,6 +13,11 @@ from textx.exceptions import TextXError import warnings +if sys.version_info >= (3, 9): + from collections.abc import Callable +else: + from typing import Callable + from .errors import InvalidQueryPath, InvalidQueryFilter, RedundantQueryFilterWarning from .query import Query diff --git a/hatchet/readers/caliper_native_reader.py b/hatchet/readers/caliper_native_reader.py index 04ae2e63..b0fa26a5 100644 --- a/hatchet/readers/caliper_native_reader.py +++ b/hatchet/readers/caliper_native_reader.py @@ -7,8 +7,13 @@ import pandas as pd import numpy as np import os +import sys from typing import Any, Dict, List, Optional, Tuple, Union, cast -from collections.abc import Callable + +if sys.version_info > (3, 9): + from collections.abc import Callable +else: + from typing import Callable import caliperreader as cr diff --git a/hatchet/readers/caliper_reader.py b/hatchet/readers/caliper_reader.py index e8ae25f3..6c616ccd 100644 --- a/hatchet/readers/caliper_reader.py +++ b/hatchet/readers/caliper_reader.py @@ -10,9 +10,13 @@ import os import math from typing import Any, Dict, List, Union, cast -from collections.abc import Callable from io import TextIOWrapper +if sys.version_info >= (3, 9): + from collections.abc import Callable +else: + from typing import Callable + import pandas as pd import numpy as np diff --git a/hatchet/readers/literal_reader.py b/hatchet/readers/literal_reader.py index 8f2b5f71..76dfba2e 100644 --- a/hatchet/readers/literal_reader.py +++ b/hatchet/readers/literal_reader.py @@ -3,8 +3,13 @@ # # SPDX-License-Identifier: MIT +import sys from typing import Any, Dict, List, cast -from collections.abc import Iterable + +if sys.version_info >= (3, 9): + from collections.abc import Iterable +else: + from typing import Iterable import pandas as pd diff --git a/hatchet/readers/tau_reader.py b/hatchet/readers/tau_reader.py index 8cebab25..4d50cbe4 100644 --- a/hatchet/readers/tau_reader.py +++ b/hatchet/readers/tau_reader.py @@ -6,9 +6,15 @@ import re import os import glob +import sys from typing import Any, Dict, List, Tuple, Union, cast -from collections.abc import Iterable import pandas as pd + +if sys.version_info >= (3, 9): + from collections.abc import Iterable +else: + from typing import Iterable + import hatchet.graphframe from hatchet.node import Node from hatchet.graph import Graph