diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d42f1d30d..e283621ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,18 +34,18 @@ repos: - id: pyupgrade args: [--py39-plus] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.2.0 hooks: - id: ruff args: - --quiet - --fix - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.15 + rev: v0.16 hooks: - id: validate-pyproject # ----- Jupyter Notebooks ----- diff --git a/CHANGELOG.md b/CHANGELOG.md index df56ffb2c..8c219869a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,20 @@ # Release Notes +## 0.6.8 (unreleased) + +### Changes + +- use pandas.to_timedelta function to pass units to the TimeDeltaIndex object \[{pull}`918`\]. + +### Dependencies + +- unpin nbval testing dependency. + ## 0.6.7 (2023.08.24) ### Added -- added `weldx.exceptions` module with `WeldxException` \[{pull}`871`\] . +- added `weldx.exceptions` module with `WeldxException` \[{pull}`871`\]. ### Fixes diff --git a/conftest.py b/conftest.py index 2442ac0e4..944736707 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,5 @@ """PyTest configuration.""" + import pytest collect_ignore_glob = [ diff --git a/devtools/scripts/clean_notebooks.py b/devtools/scripts/clean_notebooks.py index 2e6bcb02f..445f150d4 100644 --- a/devtools/scripts/clean_notebooks.py +++ b/devtools/scripts/clean_notebooks.py @@ -1,4 +1,5 @@ """Clean up jupyter notebooks in main directory.""" + from __future__ import annotations import json diff --git a/devtools/scripts/update_manifest.py b/devtools/scripts/update_manifest.py index 228d39b07..a38ca4cf9 100644 --- a/devtools/scripts/update_manifest.py +++ b/devtools/scripts/update_manifest.py @@ -1,4 +1,5 @@ """Update the manifest file with schema files found in this directory.""" + from pathlib import Path import yaml diff --git a/doc/src/tutorials/util.py b/doc/src/tutorials/util.py index fc5a9eb68..b8f66afcb 100644 --- a/doc/src/tutorials/util.py +++ b/doc/src/tutorials/util.py @@ -1,4 +1,5 @@ """Common util functions used in weldx tutorials.""" + from pathlib import Path tutorials_dir = Path(__file__).parent.absolute() diff --git a/pyproject.toml b/pyproject.toml index e65f52b13..d06cc4ff9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ requires-python = ">=3.9" dependencies = [ "numpy >=1.20", "asdf >=2.15.1", - "pandas >=1.0", + "pandas >=1.5", "xarray >=2022.9.0", "scipy >=1.6.2", "sympy >=1.6", @@ -64,7 +64,7 @@ test = [ "pytest >=6", "pytest-cov", "pytest-xdist", - "nbval <0.10", + "nbval", ] vis = [ "weldx_widgets >=0.2", @@ -125,6 +125,7 @@ filterwarnings = [ "ignore::DeprecationWarning:traittypes.*:", "ignore:Passing method to :FutureWarning:xarray.*:", "error::pint.UnitStrippedWarning", + #"error::FutureWarning", # todo: we want to enable this, as it notifies us about upcoming failures due to upstream changes. ] [tool.coverage.run] diff --git a/weldx/__init__.py b/weldx/__init__.py index 14ea4fe47..06e153059 100644 --- a/weldx/__init__.py +++ b/weldx/__init__.py @@ -116,6 +116,7 @@ asdf.validators """ + # isort:skip_file import warnings diff --git a/weldx/asdf/__init__.py b/weldx/asdf/__init__.py index 456ea2002..21b873141 100644 --- a/weldx/asdf/__init__.py +++ b/weldx/asdf/__init__.py @@ -1,4 +1,5 @@ """This submodule contains ASDF related weldx extensions and schemas.""" + # isort:skip_file from weldx import tags # implement tags before the asdf extensions here just to be safe diff --git a/weldx/asdf/cli/welding_schema.py b/weldx/asdf/cli/welding_schema.py index 7e1ad814e..2409a8131 100644 --- a/weldx/asdf/cli/welding_schema.py +++ b/weldx/asdf/cli/welding_schema.py @@ -1,4 +1,5 @@ """single_pass_weld schema.""" + from __future__ import annotations import sys diff --git a/weldx/asdf/extension.py b/weldx/asdf/extension.py index d84cdda21..935fbcb12 100644 --- a/weldx/asdf/extension.py +++ b/weldx/asdf/extension.py @@ -1,4 +1,5 @@ """ASDF-extensions for weldx types.""" + from __future__ import annotations from asdf.extension import ManifestExtension diff --git a/weldx/asdf/file.py b/weldx/asdf/file.py index e0317c06c..d5cf4fd03 100644 --- a/weldx/asdf/file.py +++ b/weldx/asdf/file.py @@ -1,4 +1,5 @@ """`WeldxFile` wraps creation and updating of ASDF files and underlying files.""" + from __future__ import annotations import copy @@ -211,8 +212,7 @@ def __init__( write_kwargs: Mapping = None, tree: Mapping = None, sync: bool = True, - custom_schema: None - | ( + custom_schema: None | ( types_path_like, tuple[None, types_path_like], ) = None, diff --git a/weldx/asdf/util.py b/weldx/asdf/util.py index c7de94c57..a608b5de1 100644 --- a/weldx/asdf/util.py +++ b/weldx/asdf/util.py @@ -1,4 +1,5 @@ """Utilities for asdf files.""" + from __future__ import annotations from collections.abc import Callable, Hashable, Mapping, MutableMapping, Set diff --git a/weldx/asdf/validators.py b/weldx/asdf/validators.py index 18d63cf77..9d8f68773 100644 --- a/weldx/asdf/validators.py +++ b/weldx/asdf/validators.py @@ -1,4 +1,5 @@ """ASDF-validators for weldx types.""" + from __future__ import annotations import re diff --git a/weldx/config.py b/weldx/config.py index 400f0d6af..9033225a5 100644 --- a/weldx/config.py +++ b/weldx/config.py @@ -1,4 +1,5 @@ """Classes and functions to configure the WelDX package.""" + from __future__ import annotations from pathlib import Path diff --git a/weldx/constants.py b/weldx/constants.py index 7f15c2821..1fe816d2c 100644 --- a/weldx/constants.py +++ b/weldx/constants.py @@ -1,4 +1,5 @@ """Define constants for global library use.""" + from pathlib import Path as _Path import pint diff --git a/weldx/core/__init__.py b/weldx/core/__init__.py index 94922e80f..d306343d5 100644 --- a/weldx/core/__init__.py +++ b/weldx/core/__init__.py @@ -1,4 +1,5 @@ """Collection of common classes and functions.""" + # isort:skip_file from weldx.core.math_expression import MathematicalExpression from weldx.core.generic_series import GenericSeries diff --git a/weldx/core/generic_series.py b/weldx/core/generic_series.py index 83849c00d..9c8eeb2a9 100644 --- a/weldx/core/generic_series.py +++ b/weldx/core/generic_series.py @@ -1,4 +1,5 @@ """Contains GenericSeries class.""" + from __future__ import annotations from collections.abc import Callable, Mapping diff --git a/weldx/core/math_expression.py b/weldx/core/math_expression.py index 9c3e19458..8edf3363d 100644 --- a/weldx/core/math_expression.py +++ b/weldx/core/math_expression.py @@ -1,4 +1,5 @@ """Contains the MathematicalExpression class.""" + from __future__ import annotations from typing import Any, Union diff --git a/weldx/core/spatial_series.py b/weldx/core/spatial_series.py index a3660b693..7981bed3d 100644 --- a/weldx/core/spatial_series.py +++ b/weldx/core/spatial_series.py @@ -1,4 +1,5 @@ """Contains the SpatialSeries class.""" + from __future__ import annotations import pint diff --git a/weldx/core/time_series.py b/weldx/core/time_series.py index acfd434fb..64abdec3d 100644 --- a/weldx/core/time_series.py +++ b/weldx/core/time_series.py @@ -1,4 +1,5 @@ """Contains TimeSeries class.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any diff --git a/weldx/geometry.py b/weldx/geometry.py index b7f9818be..8c20085be 100644 --- a/weldx/geometry.py +++ b/weldx/geometry.py @@ -1,4 +1,5 @@ """Provides classes to define lines and surfaces.""" + from __future__ import annotations import copy diff --git a/weldx/schemas/weldx.bam.de/weldx/time/time-0.1.0.yaml b/weldx/schemas/weldx.bam.de/weldx/time/time-0.1.0.yaml index ddb82852a..0274cb826 100644 --- a/weldx/schemas/weldx.bam.de/weldx/time/time-0.1.0.yaml +++ b/weldx/schemas/weldx.bam.de/weldx/time/time-0.1.0.yaml @@ -34,7 +34,7 @@ examples: values: ! start: ! '2021-01-01T00:00:00' end: ! '2021-01-01T00:00:02' - freq: S + freq: s min: ! '2021-01-01T00:00:00' max: ! '2021-01-01T00:00:02' reference_time: ! '2021-01-01T00:00:00' diff --git a/weldx/schemas/weldx.bam.de/weldx/time/timedeltaindex-0.1.0.yaml b/weldx/schemas/weldx.bam.de/weldx/time/timedeltaindex-0.1.0.yaml index cf83e4f85..e5a8c5587 100644 --- a/weldx/schemas/weldx.bam.de/weldx/time/timedeltaindex-0.1.0.yaml +++ b/weldx/schemas/weldx.bam.de/weldx/time/timedeltaindex-0.1.0.yaml @@ -13,7 +13,7 @@ examples: ! start: ! P0DT0H0M0S end: ! P0DT0H0M10S - freq: 2S + freq: 2s min: ! P0DT0H0M0S max: ! P0DT0H0M10S - diff --git a/weldx/tags/base_types.py b/weldx/tags/base_types.py index 3136157fb..6bb6bc582 100644 --- a/weldx/tags/base_types.py +++ b/weldx/tags/base_types.py @@ -1,4 +1,5 @@ """Module providing ASDF implementations for basic python types.""" + from uuid import UUID from asdf.asdf import SerializationContext diff --git a/weldx/tags/core/data_array.py b/weldx/tags/core/data_array.py index 2cd8d62e9..e4c25269f 100644 --- a/weldx/tags/core/data_array.py +++ b/weldx/tags/core/data_array.py @@ -1,4 +1,5 @@ """Serialization for xarray.DataArray.""" + from __future__ import annotations import pint diff --git a/weldx/tags/core/file.py b/weldx/tags/core/file.py index 49741e9de..c011242ae 100644 --- a/weldx/tags/core/file.py +++ b/weldx/tags/core/file.py @@ -1,4 +1,5 @@ """Contains classes for the asdf serialization of an external file.""" + from copy import deepcopy import numpy as np diff --git a/weldx/tags/core/media_file.py b/weldx/tags/core/media_file.py index 5f021aa27..3d54fad3d 100644 --- a/weldx/tags/core/media_file.py +++ b/weldx/tags/core/media_file.py @@ -1,4 +1,5 @@ """Contains classes for the asdf serialization of media files.""" + import pathlib from weldx.asdf.types import WeldxConverter diff --git a/weldx/tags/core/time_series.py b/weldx/tags/core/time_series.py index 95bc7c202..caf6009ff 100644 --- a/weldx/tags/core/time_series.py +++ b/weldx/tags/core/time_series.py @@ -1,4 +1,5 @@ """Contains the serialization class for the weldx.core.TimeSeries.""" + from __future__ import annotations import pint diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index d6b72f574..b0aeac6eb 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -8,6 +8,14 @@ __all__ = ["TimedeltaIndexConverter"] +PANDAS_OLD_UNIT_SUFFIXES = dict(H="h", T="min", S="s", L="ms", U="us", N="ns") + + +def _handle_converted_pd_tdi_units(node: TaggedDict): + """Convert changed units in Pandas.Datetimeindex to valid values.""" + for suf in PANDAS_OLD_UNIT_SUFFIXES: + node["freq"] = node["freq"].replace(suf, PANDAS_OLD_UNIT_SUFFIXES[suf]) + class TimedeltaIndexConverter(WeldxConverter): """A simple implementation of serializing pandas TimedeltaIndex.""" @@ -33,6 +41,7 @@ def to_yaml_tree(self, obj: pd.TimedeltaIndex, tag: str, ctx) -> dict: def from_yaml_tree(self, node: dict, tag: str, ctx): """Construct TimedeltaIndex from tree.""" if "freq" in node: + _handle_converted_pd_tdi_units(node) return pd.timedelta_range( start=node["start"], end=node["end"], freq=node["freq"] ) @@ -43,6 +52,7 @@ def from_yaml_tree(self, node: dict, tag: str, ctx): def shape_from_tagged(node: TaggedDict) -> list[int]: """Calculate the shape from static tagged tree instance.""" if "freq" in node: + _handle_converted_pd_tdi_units(node) tdi_temp = pd.timedelta_range( start=str(node["start"]), # can't handle TaggedString directly end=str(node["end"]), diff --git a/weldx/tests/asdf_tests/test_asdf_aws_schema.py b/weldx/tests/asdf_tests/test_asdf_aws_schema.py index 59eaf6092..554e8a8c7 100644 --- a/weldx/tests/asdf_tests/test_asdf_aws_schema.py +++ b/weldx/tests/asdf_tests/test_asdf_aws_schema.py @@ -1,4 +1,5 @@ """Test ASDF serialization of AWS schema definitions.""" + import pytest from weldx.asdf.util import write_read_buffer_context diff --git a/weldx/tests/asdf_tests/test_asdf_base_types.py b/weldx/tests/asdf_tests/test_asdf_base_types.py index f8cc57eba..adca95d44 100644 --- a/weldx/tests/asdf_tests/test_asdf_base_types.py +++ b/weldx/tests/asdf_tests/test_asdf_base_types.py @@ -1,4 +1,5 @@ """Tests asdf implementations of python base types.""" + import uuid import numpy as np diff --git a/weldx/tests/asdf_tests/test_asdf_core.py b/weldx/tests/asdf_tests/test_asdf_core.py index 67e92bdc9..bf02d11d3 100644 --- a/weldx/tests/asdf_tests/test_asdf_core.py +++ b/weldx/tests/asdf_tests/test_asdf_core.py @@ -1,4 +1,5 @@ """Tests asdf implementations of core module.""" + from pathlib import Path from tempfile import TemporaryDirectory @@ -424,12 +425,12 @@ def test_coordinate_system_manager_time_dependencies( lcs_tdp_1_time_ref = pd.Timestamp("2000-03-17") lcs_tdp_1 = tf.LocalCoordinateSystem( coordinates=Q_([[1, 2, 3], [4, 5, 6]], "mm"), - time=pd.TimedeltaIndex([1, 2], "D"), + time=pd.to_timedelta([1, 2], "D"), time_ref=lcs_tdp_1_time_ref, ) lcs_tdp_2 = tf.LocalCoordinateSystem( coordinates=Q_([[3, 7, 3], [9, 5, 8]], "mm"), - time=pd.TimedeltaIndex([1, 2], "D"), + time=pd.to_timedelta([1, 2], "D"), time_ref=pd.Timestamp("2000-03-21"), ) diff --git a/weldx/tests/asdf_tests/test_asdf_graph.py b/weldx/tests/asdf_tests/test_asdf_graph.py index 30fcf9adf..d40637f1d 100644 --- a/weldx/tests/asdf_tests/test_asdf_graph.py +++ b/weldx/tests/asdf_tests/test_asdf_graph.py @@ -1,4 +1,5 @@ """Test graph serializations.""" + import unittest from uuid import uuid4 diff --git a/weldx/tests/asdf_tests/test_asdf_groove.py b/weldx/tests/asdf_tests/test_asdf_groove.py index e5e45008c..aad47afe3 100644 --- a/weldx/tests/asdf_tests/test_asdf_groove.py +++ b/weldx/tests/asdf_tests/test_asdf_groove.py @@ -1,4 +1,5 @@ """Test all ASDF groove implementations.""" + import pytest from decorator import contextmanager diff --git a/weldx/tests/asdf_tests/test_asdf_time.py b/weldx/tests/asdf_tests/test_asdf_time.py index fe85e64a0..b2171c89e 100644 --- a/weldx/tests/asdf_tests/test_asdf_time.py +++ b/weldx/tests/asdf_tests/test_asdf_time.py @@ -1,4 +1,5 @@ """Test time schema implementation.""" + import numpy as np import pandas as pd import pytest diff --git a/weldx/tests/asdf_tests/test_asdf_util.py b/weldx/tests/asdf_tests/test_asdf_util.py index 9ae9f2a50..ed7c62416 100644 --- a/weldx/tests/asdf_tests/test_asdf_util.py +++ b/weldx/tests/asdf_tests/test_asdf_util.py @@ -1,4 +1,5 @@ """tests for asdf utility functions.""" + from __future__ import annotations import io diff --git a/weldx/tests/asdf_tests/test_asdf_validators.py b/weldx/tests/asdf_tests/test_asdf_validators.py index e838860af..3f6b76f69 100644 --- a/weldx/tests/asdf_tests/test_asdf_validators.py +++ b/weldx/tests/asdf_tests/test_asdf_validators.py @@ -1,4 +1,5 @@ """Test custom weldx ASDF validator functions.""" + import numpy as np import pandas as pd import pytest diff --git a/weldx/tests/asdf_tests/test_media_file.py b/weldx/tests/asdf_tests/test_media_file.py index 34e290f43..3dc9358c5 100644 --- a/weldx/tests/asdf_tests/test_media_file.py +++ b/weldx/tests/asdf_tests/test_media_file.py @@ -1,4 +1,5 @@ """Tests for MediaFile.""" + import numpy as np import pytest import xarray as xr diff --git a/weldx/tests/asdf_tests/test_weldx_file.py b/weldx/tests/asdf_tests/test_weldx_file.py index 863159abf..2bfbd956f 100644 --- a/weldx/tests/asdf_tests/test_weldx_file.py +++ b/weldx/tests/asdf_tests/test_weldx_file.py @@ -1,4 +1,5 @@ """Tests for the WeldxFile class.""" + import itertools import os import pathlib diff --git a/weldx/tests/conftest.py b/weldx/tests/conftest.py index b4c5dce62..8f48f8bfc 100644 --- a/weldx/tests/conftest.py +++ b/weldx/tests/conftest.py @@ -1,4 +1,5 @@ """pytest configuration.""" + import pytest from weldx.asdf.cli.welding_schema import single_pass_weld_example diff --git a/weldx/tests/test_config.py b/weldx/tests/test_config.py index 02e9bf0fc..d8d8e0cd1 100644 --- a/weldx/tests/test_config.py +++ b/weldx/tests/test_config.py @@ -1,4 +1,5 @@ """Test the `config` module.""" + from pathlib import Path import asdf diff --git a/weldx/tests/test_core.py b/weldx/tests/test_core.py index a8ac6cdd8..1e44a8ceb 100644 --- a/weldx/tests/test_core.py +++ b/weldx/tests/test_core.py @@ -1,4 +1,5 @@ """Tests of the core package.""" + import warnings import numpy as np @@ -227,10 +228,9 @@ class TestTimeSeries: ME = MathematicalExpression DTI = pd.DatetimeIndex - TDI = pd.TimedeltaIndex TS = TimeSeries - time_discrete = pd.TimedeltaIndex([0, 1, 2, 3, 4], unit="s") + time_discrete = pd.to_timedelta([0, 1, 2, 3, 4], "s") value_constant = Q_(1, "m") values_discrete = Q_(np.array([10, 11, 12, 14, 16]), "mm") me_expr_str = "a*t + b" @@ -251,7 +251,7 @@ class TestTimeSeries: "data, time, interpolation, shape_exp", [ (Q_(1, "m"), None, None, (1,)), - (Q_([3, 7, 1], "m"), TDI([0, 1, 2], unit="s"), "step", (3,)), + (Q_([3, 7, 1], "m"), pd.to_timedelta([0, 1, 2], unit="s"), "step", (3,)), (Q_([3, 7, 1], ""), Q_([0, 1, 2], "s"), "step", (3,)), (Q_([3, 7, 1], ""), DTI(["2010", "2011", "2012"]), "step", (3,)), ], @@ -329,12 +329,17 @@ def test_construction_expression(data, shape_exp, unit_exp): @pytest.mark.parametrize( "data, dims, coords, exception_type", [ - (Q_([1, 2, 3], "m"), "time", dict(time=TDI([1, 2, 3])), None), - (Q_([1, 2, 3], "m"), "a", dict(a=TDI([1, 2, 3])), KeyError), - (Q_([[1, 2]], "m"), ("a", "time"), dict(a=[2], time=TDI([1, 2])), None), + (Q_([1, 2, 3], "m"), "time", dict(time=pd.to_timedelta([1, 2, 3])), None), + (Q_([1, 2, 3], "m"), "a", dict(a=pd.to_timedelta([1, 2, 3])), KeyError), + ( + Q_([[1, 2]], "m"), + ("a", "time"), + dict(a=[2], time=pd.to_timedelta([1, 2])), + None, + ), (Q_([1, 2, 3], "m"), "time", None, KeyError), (Q_([1, 2, 3], "m"), "time", dict(time=[1, 2, 3]), TypeError), - ([1, 2, 3], "time", dict(time=TDI([1, 2, 3])), TypeError), + ([1, 2, 3], "time", dict(time=pd.to_timedelta([1, 2, 3])), TypeError), ], ) @pytest.mark.parametrize("reference_time", [None, "2000-01-01"]) @@ -382,7 +387,7 @@ def test_construction_exceptions( # test_comparison ------------------------------------- - time_wrong_values = TDI([0, 1, 2, 3, 5], unit="s") + time_wrong_values = pd.to_timedelta([0, 1, 2, 3, 5], "s") values_discrete_wrong = Q_(np.array([10, 11, 12, 15, 16]), "mm") values_unit_wrong = Q_(np.array([10, 11, 12, 14, 16]), "s") values_unit_prefix_wrong = Q_(np.array([10, 11, 12, 14, 16]), "m") @@ -426,9 +431,9 @@ def test_comparison(ts, ts_other, result_exp): # test_interp_time ----------------------------------------------------------------- - time_single = pd.TimedeltaIndex([2.1], "s") + time_single = pd.to_timedelta([2.1], "s") time_single_q = Q_(2.1, "s") - time_mul = pd.TimedeltaIndex([-3, 0.7, 1.1, 1.9, 2.5, 3, 4, 7], "s") + time_mul = pd.to_timedelta([-3, 0.7, 1.1, 1.9, 2.5, 3, 4, 7], "s") time_mul_q = Q_([-3, 0.7, 1.1, 1.9, 2.5, 3, 4, 7], "s") results_exp_vec = [ [-8, 3, -3], diff --git a/weldx/tests/test_geometry.py b/weldx/tests/test_geometry.py index f1a41c8bd..c31535915 100644 --- a/weldx/tests/test_geometry.py +++ b/weldx/tests/test_geometry.py @@ -1,4 +1,5 @@ """Tests the geometry package.""" + from __future__ import annotations import copy diff --git a/weldx/tests/test_measurement.py b/weldx/tests/test_measurement.py index 19a14d5c4..93c1c2c0e 100644 --- a/weldx/tests/test_measurement.py +++ b/weldx/tests/test_measurement.py @@ -1,4 +1,5 @@ """Test the measurement package.""" + from __future__ import annotations import numpy as np diff --git a/weldx/tests/test_time.py b/weldx/tests/test_time.py index 8e979fdad..fa6d2cbdd 100644 --- a/weldx/tests/test_time.py +++ b/weldx/tests/test_time.py @@ -1,4 +1,5 @@ """Test the `Time` class.""" + from __future__ import annotations import numpy as np @@ -7,7 +8,6 @@ import xarray as xr from pandas import DatetimeIndex as DTI from pandas import Timedelta, Timestamp, date_range -from pandas import TimedeltaIndex as TDI from pint import DimensionalityError from weldx.constants import Q_ @@ -77,7 +77,7 @@ def _initialize_time_type( def _is_timedelta(cls_type): """Return ``True`` if the passed type is a timedelta type.""" - return cls_type in [TDI, Timedelta, np.timedelta64] or ( + return cls_type in [pd.to_timedelta, Timedelta, np.timedelta64] or ( cls_type is Time and not Time.is_absolute ) @@ -143,7 +143,9 @@ def _get_init_exp_values( val = [v + offset for v in delta_val] val = val[0] if data_was_scalar else val - exp_timedelta = Timedelta(val, "s") if data_was_scalar else TDI(val, "s") + exp_timedelta = ( + Timedelta(val, "s") if data_was_scalar else pd.to_timedelta(val, "s") + ) # expected datetime exp_datetime = None @@ -168,7 +170,7 @@ def _get_init_exp_values( (str, "timedelta"), (Time, "timedelta"), (Q_, "timedelta"), - TDI, + pd.to_timedelta, Timedelta, np.timedelta64, (str, "datetime"), @@ -209,7 +211,7 @@ def test_init( # skip matrix cases that do not work -------------------- if arr and input_type in [Timedelta, Timestamp]: return - if not arr and input_type in [DTI, TDI]: + if not arr and input_type in [DTI, pd.to_timedelta]: return # create input values ----------------------------------- @@ -247,7 +249,7 @@ def test_init( LocalCoordinateSystem( coordinates=Q_(np.zeros((2, 3)), "mm"), time=["2000", "2001"] ), - TimeSeries(Q_([2, 4, 1], "m"), TDI([1, 2, 3], "s")), + TimeSeries(Q_([2, 4, 1], "m"), pd.to_timedelta([1, 2, 3], "s")), TimeSeries(Q_([2, 4, 1], "m"), ["2001", "2002", "2003"]), ], ) @@ -262,7 +264,7 @@ def test_init_from_time_dependent_types(time_dep_type): @pytest.mark.parametrize( "time, time_ref, raises", [ - (TDI([3, 2, 1]), None, ValueError), + (pd.to_timedelta([3, 2, 1]), None, ValueError), (DTI(["2010", "2000"]), None, ValueError), (["2010", "2000"], None, ValueError), (Q_([3, 2, 1], "s"), None, ValueError), @@ -290,7 +292,7 @@ def test_init_exception(time, time_ref, raises): (str, "timedelta"), (Time, "timedelta"), (Q_, "timedelta"), - TDI, + pd.to_timedelta, Timedelta, np.timedelta64, (str, "datetime"), @@ -331,7 +333,7 @@ def test_add_timedelta( # skip array cases where the type does not support arrays if other_type in [Timedelta, Timestamp] and other_is_array: return - if not other_is_array and other_type in [DTI, TDI]: + if not other_is_array and other_type in [DTI, pd.to_timedelta]: return # skip __radd__ cases where we got conflicts with the other types' __add__ @@ -341,7 +343,7 @@ def test_add_timedelta( np.timedelta64, np.datetime64, DTI, - TDI, + pd.to_timedelta, ): return @@ -392,7 +394,7 @@ def test_add_timedelta( str, Time, Q_, - TDI, + pd.to_timedelta, Timedelta, np.timedelta64, ], @@ -421,11 +423,16 @@ def test_add_datetime( # skip array cases where the type does not support arrays if other_type in [Timedelta, Timestamp] and other_is_array: return - if not other_is_array and other_type in [DTI, TDI]: + if not other_is_array and other_type in [DTI, pd.to_timedelta]: return # skip __radd__ cases where we got conflicts with the other types' __add__ - if not other_on_rhs and other_type in (Q_, np.ndarray, np.timedelta64, TDI): + if not other_on_rhs and other_type in ( + Q_, + np.ndarray, + np.timedelta64, + pd.to_timedelta, + ): return # setup rhs @@ -477,7 +484,7 @@ def _date_diff(date_1: str, date_2: str, unit: str) -> int: (str, "timedelta"), (Time, "timedelta"), (Q_, "timedelta"), - TDI, + pd.to_timedelta, Timedelta, np.timedelta64, (str, "datetime"), @@ -532,7 +539,7 @@ def test_sub( # skip array cases where the type does not support arrays or scalars if other_type in [Timedelta, Timestamp] and other_is_array: return - if not other_is_array and other_type in [DTI, TDI]: + if not other_is_array and other_type in [DTI, pd.to_timedelta]: return # skip __rsub__ cases where we got conflicts with the other types' __sub__ @@ -542,7 +549,7 @@ def test_sub( np.timedelta64, np.datetime64, DTI, - TDI, + pd.to_timedelta, ): return @@ -612,13 +619,16 @@ def test_sub( "arg, expected", [ # timedeltas - (TDI([42], unit="ns"), TDI([42], unit="ns")), + (pd.to_timedelta([42], unit="ns"), pd.to_timedelta([42], unit="ns")), (pd.timedelta_range("0s", "20s", 10), pd.timedelta_range("0s", "20s", 10)), - (np.timedelta64(42), TDI([42], unit="ns")), - (np.array([-10, 0, 20]).astype("timedelta64[ns]"), TDI([-10, 0, 20], "ns")), - (Q_(42, "ns"), TDI([42], unit="ns")), - ("10s", TDI(["10s"])), - (["5ms", "10s", "2D"], TDI(["5 ms", "10s", "2D"])), + (np.timedelta64(42), pd.to_timedelta([42], unit="ns")), + ( + np.array([-10, 0, 20]).astype("timedelta64[ns]"), + pd.to_timedelta([-10, 0, 20], "ns"), + ), + (Q_(42, "ns"), pd.to_timedelta([42], unit="ns")), + ("10s", pd.to_timedelta(["10s"])), + (["5ms", "10s", "2D"], pd.to_timedelta(["5 ms", "10s", "2D"])), # datetimes (np.datetime64(50, "Y"), DTI(["2020-01-01"])), ("2020-01-01", DTI(["2020-01-01"])), @@ -647,10 +657,10 @@ def test_pandas_index(arg, expected): ("1s", "ms", 1000), ("1s", "us", 1000000), ("1s", "ns", 1000000000), - (TDI([1, 2, 3], "s"), "s", [1, 2, 3]), - (TDI([1, 2, 3], "s"), "ms", np.array([1, 2, 3]) * 1e3), - (TDI([1, 2, 3], "s"), "us", np.array([1, 2, 3]) * 1e6), - (TDI([1, 2, 3], "s"), "ns", np.array([1, 2, 3]) * 1e9), + (pd.to_timedelta([1, 2, 3], "s"), "s", [1, 2, 3]), + (pd.to_timedelta([1, 2, 3], "s"), "ms", np.array([1, 2, 3]) * 1e3), + (pd.to_timedelta([1, 2, 3], "s"), "us", np.array([1, 2, 3]) * 1e6), + (pd.to_timedelta([1, 2, 3], "s"), "ns", np.array([1, 2, 3]) * 1e9), ("2020-01-01", "s", 0), ], ) @@ -775,7 +785,14 @@ def test_resample_exceptions(values, number_or_interval, raises): ], date_range("2020-02-01", periods=8, freq="1D"), ), - ([TDI([1, 5]), TDI([2, 6, 7]), TDI([1, 3, 7])], TDI([1, 2, 3, 5, 6, 7])), + ( + [ + pd.to_timedelta([1, 5]), + pd.to_timedelta([2, 6, 7]), + pd.to_timedelta([1, 3, 7]), + ], + pd.to_timedelta([1, 2, 3, 5, 6, 7]), + ), ], ) @pytest.mark.parametrize("test_instance", [True, False]) diff --git a/weldx/tests/test_utility.py b/weldx/tests/test_utility.py index 6658fd3a9..69d2f5305 100644 --- a/weldx/tests/test_utility.py +++ b/weldx/tests/test_utility.py @@ -1,4 +1,5 @@ """Test the internal utility functions.""" + from __future__ import annotations import copy @@ -333,7 +334,7 @@ def test_xr_fill_all(): "d1": np.array([-1, 1], dtype=float), "d2": np.array([-1, 1], dtype=int), "d3": pd.DatetimeIndex(["2020-05-01", "2020-05-03"]), - "d4": pd.TimedeltaIndex([0, 1, 2, 3], "s"), + "d4": pd.to_timedelta([0, 1, 2, 3], "s"), "d5": ["x", "y", "z"], }, ) @@ -352,7 +353,7 @@ def test_xr_fill_all(): "dtype": ["datetime64[ns]", "timedelta64[ns]"], }, d4={ - "values": pd.TimedeltaIndex([0, 1, 2, 3], "s"), + "values": pd.to_timedelta([0, 1, 2, 3], "s"), "dtype": ["datetime64[ns]", "timedelta64[ns]"], }, d5={"values": ["x", "y", "z"], "dtype": " dict[str, tuple[str, np.ndarray, dict[str, pint.Unit]]]: """Create a dict with unit information that can be passed as coords for xarray.""" return { - k: (k, v.m, {UNITS_KEY: v.u}) # type: ignore[dict-item] - if isinstance(v, pint.Quantity) - else v + k: ( + (k, v.m, {UNITS_KEY: v.u}) # type: ignore[dict-item] + if isinstance(v, pint.Quantity) + else v + ) for k, v in q_dict.items() } diff --git a/weldx/visualization/__init__.py b/weldx/visualization/__init__.py index 94cfd60e4..98174f7e0 100644 --- a/weldx/visualization/__init__.py +++ b/weldx/visualization/__init__.py @@ -44,17 +44,11 @@ def __init__(self, *args, **kwargs): CoordinateSystemManagerVisualizerK3D = _Hint SpatialDataVisualizer = _Hint - axes_equal = ( - draw_coordinate_system_matplotlib - ) = ( - new_3d_figure_and_axes - ) = ( + axes_equal = draw_coordinate_system_matplotlib = new_3d_figure_and_axes = ( plot_coordinate_system_manager_matplotlib - ) = ( - plot_coordinate_systems - ) = ( - plot_local_coordinate_system_matplotlib - ) = plot_spatial_data_matplotlib = _warn + ) = plot_coordinate_systems = plot_local_coordinate_system_matplotlib = ( + plot_spatial_data_matplotlib + ) = _warn else: # something else is missing, pass the exception. raise diff --git a/weldx/welding/processes.py b/weldx/welding/processes.py index 422e1b8eb..7b09046aa 100644 --- a/weldx/welding/processes.py +++ b/weldx/welding/processes.py @@ -1,4 +1,5 @@ """Welding process classes.""" + from __future__ import annotations from dataclasses import dataclass diff --git a/weldx/welding/util.py b/weldx/welding/util.py index 31b65bde2..0c5c92f65 100644 --- a/weldx/welding/util.py +++ b/weldx/welding/util.py @@ -1,4 +1,5 @@ """Collection of welding utilities.""" + from __future__ import annotations from typing import TYPE_CHECKING