From 4fac5dd7b68e664a13765ce622df77adab6a2af7 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 10:32:49 +0100 Subject: [PATCH 01/19] use pandas.to_timedelta function instead of invoking deprecated ctor (unit argument will be gone) --- .../tests/transformations/test_cs_manager.py | 35 +++++++++---------- weldx/tests/transformations/test_local_cs.py | 18 +++++----- weldx/time.py | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/weldx/tests/transformations/test_cs_manager.py b/weldx/tests/transformations/test_cs_manager.py index d3bd1a657..743e764cb 100644 --- a/weldx/tests/transformations/test_cs_manager.py +++ b/weldx/tests/transformations/test_cs_manager.py @@ -7,7 +7,6 @@ import pandas as pd import pytest import xarray as xr -from pandas import TimedeltaIndex as TDI from pandas import Timestamp as TS import weldx.transformations as tf @@ -953,7 +952,7 @@ def test_time_union_time_series_coords( ) if exp_time is not None: - exp_time = TDI(exp_time, unit="s") + exp_time = pd.to_timedelta(exp_time, unit="s") assert np.all(exp_time == csm.time_union(list_of_edges)) @@ -1378,19 +1377,19 @@ def test_get_local_coordinate_system_time_dep( time_refs = [t if t is None else pd.Timestamp(t) for t in time_refs] # moves in positive x-direction - time_1 = TDI([0, 3, 12], "D") + time_1 = pd.to_timedelta([0, 3, 12], "D") time_ref_1 = time_refs[1] orientation_1 = None coordinates_1 = Q_([[i, 0, 0] for i in [0, 0.25, 1]], "mm") # moves in negative x-direction and rotates positively around the x-axis - time_2 = TDI([0, 4, 8, 12], "D") + time_2 = pd.to_timedelta([0, 4, 8, 12], "D") time_ref_2 = time_refs[2] coordinates_2 = Q_([[-i, 0, 0] for i in [0, 1 / 3, 2 / 3, 1]], "mm") orientation_2 = r_mat_x([0, 2 / 3, 4 / 3, 2]) # rotates negatively around the x-axis - time_3 = TDI([0, 3, 6, 9, 12], "D") + time_3 = pd.to_timedelta([0, 3, 6, 9, 12], "D") time_ref_3 = time_refs[3] coordinates_3 = Q_([1, 0, 0], "mm") orientation_3 = r_mat_x([0, -0.5, -1, -1.5, -2]) @@ -1523,8 +1522,8 @@ def test_get_local_coordinate_system_exceptions( """ # setup - time_1 = TDI([0, 3], "D") - time_2 = TDI([4, 7], "D") + time_1 = pd.to_timedelta([0, 3], "D") + time_2 = pd.to_timedelta([4, 7], "D") csm = tf.CoordinateSystemManager(root_coordinate_system_name="root") csm.create_cs("cs_1", "root", r_mat_z(0.5), Q_([1, 2, 3], "mm")) @@ -1691,7 +1690,7 @@ def test_merge_reference_times( # setup lcs_static = tf.LocalCoordinateSystem(coordinates=Q_([1, 1, 1], "mm")) lcs_dynamic = tf.LocalCoordinateSystem( - coordinates=Q_([[0, 4, 2], [7, 2, 4]], "mm"), time=TDI([4, 8], "D") + coordinates=Q_([[0, 4, 2], [7, 2, 4]], "mm"), time=pd.to_timedelta([4, 8], "D") ) time_ref_parent = None if time_ref_day_parent is not None: @@ -2532,18 +2531,18 @@ def _coordinates_from_value(val, clip_min=None, clip_max=None): @pytest.mark.parametrize( "time, time_ref, systems, csm_has_time_ref, num_abs_systems", [ - (TDI([1, 7, 11, 20], "D"), None, None, False, 0), - (TDI([3], "D"), None, None, False, 0), + (pd.to_timedelta([1, 7, 11, 20], "D"), None, None, False, 0), + (pd.to_timedelta([3], "D"), None, None, False, 0), (pd.Timedelta(3, "D"), None, None, False, 0), (Q_([1, 7, 11, 20], "days"), None, None, False, 0), (["5days", "8days"], None, None, False, 0), - (TDI([1, 7, 11, 20], "D"), None, ["lcs_1"], False, 0), - (TDI([1, 7, 11, 20], "D"), None, ["lcs_1", "lcs_2"], False, 0), - (TDI([1, 7, 11, 20], "D"), "2000-01-10", None, True, 0), - (TDI([1, 7, 11, 20], "D"), "2000-01-13", None, True, 0), - (TDI([1, 7, 11, 20], "D"), "2000-01-13", None, False, 3), - (TDI([1, 7, 11, 20], "D"), "2000-01-13", None, True, 3), - (TDI([1, 7, 11, 20], "D"), "2000-01-13", None, True, 2), + (pd.to_timedelta([1, 7, 11, 20], "D"), None, ["lcs_1"], False, 0), + (pd.to_timedelta([1, 7, 11, 20], "D"), None, ["lcs_1", "lcs_2"], False, 0), + (pd.to_timedelta([1, 7, 11, 20], "D"), "2000-01-10", None, True, 0), + (pd.to_timedelta([1, 7, 11, 20], "D"), "2000-01-13", None, True, 0), + (pd.to_timedelta([1, 7, 11, 20], "D"), "2000-01-13", None, False, 3), + (pd.to_timedelta([1, 7, 11, 20], "D"), "2000-01-13", None, True, 3), + (pd.to_timedelta([1, 7, 11, 20], "D"), "2000-01-13", None, True, 2), (["2000-01-13", "2000-01-17"], None, None, True, 2), ], ) @@ -2745,7 +2744,7 @@ def test_coordinate_system_manager_create_coordinate_system(): rot_mat_x = WXRotation.from_euler("x", angles_x).as_matrix() rot_mat_y = WXRotation.from_euler("y", angles_y).as_matrix() - time = TDI([0, 6, 12, 18], "H") + time = pd.to_timedelta([0, 6, 12, 18], "h") orientations = np.matmul(rot_mat_x, rot_mat_y) coords = Q_([[1, 0, 0], [-1, 0, 2], [3, 5, 7], [-4, -5, -6]], "mm") diff --git a/weldx/tests/transformations/test_local_cs.py b/weldx/tests/transformations/test_local_cs.py index 8445db843..1bb1ff03e 100644 --- a/weldx/tests/transformations/test_local_cs.py +++ b/weldx/tests/transformations/test_local_cs.py @@ -401,7 +401,7 @@ def test_reset_reference_time_exceptions( """ orientation = WXRotation.from_euler("z", [1, 2, 3]).as_matrix() coordinates = Q_([[i, i, i] for i in range(3)], "mm") - time = TDI([1, 2, 3], "D") + time = pd.to_timedelta([1, 2, 3], "D") lcs = tf.LocalCoordinateSystem(orientation, coordinates, time, time_ref=time_ref) @@ -483,7 +483,7 @@ def test_interp_time_discrete( lcs = tf.LocalCoordinateSystem( orientation=r_mat_z([0, 0.5, 1, 0.5]), coordinates=Q_([[2, 8, 7], [4, 9, 2], [0, 2, 1], [3, 1, 2]], "mm"), - time=TDI([10, 14, 18, 22], "D"), + time=pd.to_timedelta([10, 14, 18, 22], "D"), time_ref=time_ref_lcs, ) @@ -736,7 +736,7 @@ def test_interp_time_exceptions( """ orientation = r_mat_z([1, 2, 3]) coordinates = Q_([[i, i, i] for i in range(3)], "mm") - time_lcs = TDI([1, 2, 3], "D") + time_lcs = pd.to_timedelta([1, 2, 3], "D") lcs = tf.LocalCoordinateSystem( orientation, coordinates, time_lcs, time_ref=time_ref_lcs @@ -1184,8 +1184,8 @@ def test_comparison_coords_timeseries( def test_coordinate_system_init(): """Check the __init__ method with and without time dependency.""" # reference data - time_0 = TDI([1, 3, 5], "s") - time_1 = TDI([2, 4, 6], "s") + time_0 = pd.to_timedelta([1, 3, 5], "s") + time_1 = pd.to_timedelta([2, 4, 6], "s") orientation_fix = r_mat_z(1) orientation_tdp = r_mat_z([0, 0.25, 0.5]) @@ -1261,7 +1261,7 @@ def test_coordinate_system_init(): orientation=xr_orientation_tdp_0, coordinates=xr_coordinates_tdp_1 ) - time_exp = TDI([1, 2, 3, 4, 5, 6], "s") + time_exp = pd.to_timedelta([1, 2, 3, 4, 5, 6], "s") coordinates_exp = Q_( [ [3, 7, 1], @@ -1366,7 +1366,7 @@ def test_coordinate_system_factories_time_dependent(): rot_mat_x = WXRotation.from_euler("x", angles_x).as_matrix() rot_mat_y = WXRotation.from_euler("y", angles_y).as_matrix() - time = TDI([0, 6, 12, 18], "H") + time = pd.to_timedelta([0, 6, 12, 18], "h") orientations = np.matmul(rot_mat_x, rot_mat_y) coords = Q_([[1, 0, 0], [-1, 0, 2], [3, 5, 7], [-4, -5, -6]], "mm") @@ -1408,7 +1408,7 @@ def test_coordinate_system_invert(): ) # time dependent ---------------------------- - time = TDI([1, 2, 3, 4], "s") + time = pd.to_timedelta([1, 2, 3, 4], "s") orientation = r_mat_z([0, 0.5, 1, 0.5]) coordinates = Q_([[2, 8, 7], [4, 9, 2], [0, 2, 1], [3, 1, 2]], "mm") @@ -1467,7 +1467,7 @@ def coordinate_system_time_interpolation_test_case( def test_coordinate_system_time_interpolation(): """Test the local coordinate systems interp_time and interp_like functions.""" - time_0 = TDI([10, 14, 18, 22], "D") + time_0 = pd.to_timedelta([10, 14, 18, 22], "D") orientation = r_mat_z([0, 0.5, 1, 0.5]) coordinates = Q_([[2, 8, 7], [4, 9, 2], [0, 2, 1], [3, 1, 2]], "mm") diff --git a/weldx/time.py b/weldx/time.py index 5095f9d91..5b5c7e1b9 100644 --- a/weldx/time.py +++ b/weldx/time.py @@ -670,7 +670,7 @@ def _convert_quantity( # necessary interfaces so that the function works as expected time = np.expand_dims(time, 0) # type: ignore[assignment] - delta = pd.TimedeltaIndex(data=time.to(base).magnitude, unit=base) + delta = pd.to_timedelta(time.to(base).magnitude, base) if time_ref is not None: delta = delta + time_ref return delta From 98007cbe0bc9f5eee0d0778b217555b840ff5238 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 10:57:57 +0100 Subject: [PATCH 02/19] fix schema example unit --- weldx/schemas/weldx.bam.de/weldx/time/time-0.1.0.yaml | 2 +- weldx/schemas/weldx.bam.de/weldx/time/timedeltaindex-0.1.0.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 - From d17fa7e9381f6ea1b2ebbaf7fdb75edeaedecebd Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:04:35 +0100 Subject: [PATCH 03/19] fix timedeltaindex convert --- weldx/tags/time/timedeltaindex.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index d6b72f574..0386f28a8 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -9,6 +9,14 @@ __all__ = ["TimedeltaIndexConverter"] +def _handle_converted_pd_tdi_units(node: TaggedDict): + """convert changed units in Pandas.Datetimeindex to valid valid values.""" + # TODO: extend this to other changed units, eventually only seconds + # are relevant to weldx right now, as it was used in the previous schema version. + if "S" in node["freq"]: + node["freq"] = node["freq"][:-1] + "s" + + 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"]), From 019590b15da0ee35a591456917c412a3aabcb1e3 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:05:25 +0100 Subject: [PATCH 04/19] typo --- weldx/tags/time/timedeltaindex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index 0386f28a8..ae6aa2c78 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -10,7 +10,7 @@ def _handle_converted_pd_tdi_units(node: TaggedDict): - """convert changed units in Pandas.Datetimeindex to valid valid values.""" + """convert changed units in Pandas.Datetimeindex to valid values.""" # TODO: extend this to other changed units, eventually only seconds # are relevant to weldx right now, as it was used in the previous schema version. if "S" in node["freq"]: From 4dae9cb4c744ed26c9492b4e4c5038f9be4ca052 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:16:09 +0100 Subject: [PATCH 05/19] typo --- weldx/tags/time/timedeltaindex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index ae6aa2c78..d96d180fd 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -10,7 +10,7 @@ def _handle_converted_pd_tdi_units(node: TaggedDict): - """convert changed units in Pandas.Datetimeindex to valid values.""" + """Convert changed units in Pandas.Datetimeindex to valid values.""" # TODO: extend this to other changed units, eventually only seconds # are relevant to weldx right now, as it was used in the previous schema version. if "S" in node["freq"]: From a2c952754fcddf7464b1b22d79fbda93aa2748f5 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:16:23 +0100 Subject: [PATCH 06/19] use util func --- weldx/tests/test_core.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/weldx/tests/test_core.py b/weldx/tests/test_core.py index a8ac6cdd8..3ded6821b 100644 --- a/weldx/tests/test_core.py +++ b/weldx/tests/test_core.py @@ -227,10 +227,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 +250,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 +328,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 +386,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") From faac3a02c80e3aeaaa05b0b01568c0c79610a573 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:18:07 +0100 Subject: [PATCH 07/19] fix doctest --- weldx/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weldx/time.py b/weldx/time.py index 5b5c7e1b9..8aded0950 100644 --- a/weldx/time.py +++ b/weldx/time.py @@ -629,7 +629,7 @@ def resample(self, number_or_interval: int | types_timedelta_like): TimedeltaIndex([ '0 days 00:00:03', '0 days 00:00:04.500000', '0 days 00:00:06', '0 days 00:00:07.500000', '0 days 00:00:09'], - dtype='timedelta64[ns]', freq='1500L') + dtype='timedelta64[ns]', freq='1500ms') """ if len(self) <= 1: From 22f7f464187a3cf0f0cc061f704be0917c5b9b1d Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:20:24 +0100 Subject: [PATCH 08/19] use util func instead of TDI --- weldx/tests/test_time.py | 70 +++++---- weldx/tests/transformations/test_local_cs.py | 156 +++++++++++-------- 2 files changed, 131 insertions(+), 95 deletions(-) diff --git a/weldx/tests/test_time.py b/weldx/tests/test_time.py index 8e979fdad..2ca0028ee 100644 --- a/weldx/tests/test_time.py +++ b/weldx/tests/test_time.py @@ -7,7 +7,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 +76,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 +142,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 +169,7 @@ def _get_init_exp_values( (str, "timedelta"), (Time, "timedelta"), (Q_, "timedelta"), - TDI, + pd.to_timedelta, Timedelta, np.timedelta64, (str, "datetime"), @@ -209,7 +210,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 +248,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 +263,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 +291,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 +332,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 +342,7 @@ def test_add_timedelta( np.timedelta64, np.datetime64, DTI, - TDI, + pd.to_timedelta, ): return @@ -392,7 +393,7 @@ def test_add_timedelta( str, Time, Q_, - TDI, + pd.to_timedelta, Timedelta, np.timedelta64, ], @@ -421,11 +422,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 +483,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 +538,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 +548,7 @@ def test_sub( np.timedelta64, np.datetime64, DTI, - TDI, + pd.to_timedelta, ): return @@ -612,13 +618,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 +656,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 +784,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/transformations/test_local_cs.py b/weldx/tests/transformations/test_local_cs.py index 1bb1ff03e..7de20db85 100644 --- a/weldx/tests/transformations/test_local_cs.py +++ b/weldx/tests/transformations/test_local_cs.py @@ -9,7 +9,6 @@ import pint import pytest import xarray as xr -from pandas import TimedeltaIndex as TDI from pandas import Timestamp as TS from pandas import date_range from pint import DimensionalityError @@ -57,7 +56,7 @@ def test_init(orient, coords, time, time_ref, exception, data_array_coords): # test_init_time_formats --------------------------------------------------------------- timestamp = TS("2000-01-01") -time_delta = TDI([0, 1, 2], "s") +time_delta = pd.to_timedelta([0, 1, 2], "s") time_quantity = Q_([0, 1, 2], "s") date_time = date_range("2000-01-01", periods=3, freq="s") @@ -73,7 +72,7 @@ def test_init(orient, coords, time, time_ref, exception, data_array_coords): ( date_time, TS("1999-12-31"), - TDI([86400, 86401, 86402], "s"), + pd.to_timedelta([86400, 86401, 86402], "s"), TS("1999-12-31"), ), ], @@ -110,8 +109,13 @@ def test_init_time_formats(time, time_ref, time_exp, time_ref_exp): @pytest.mark.parametrize( "coordinates, orientation, time, warning", [ - (Q_(np.zeros(3), "mm"), np.eye(3, 3), TDI([0, 2], "s"), UserWarning), - (Q_(np.zeros((2, 3)), "mm"), np.eye(3, 3), TDI([0, 2], "s"), None), + ( + Q_(np.zeros(3), "mm"), + np.eye(3, 3), + pd.to_timedelta([0, 2], "s"), + UserWarning, + ), + (Q_(np.zeros((2, 3)), "mm"), np.eye(3, 3), pd.to_timedelta([0, 2], "s"), None), (Q_(np.zeros(3), "mm"), np.eye(3, 3), None, None), ], ) @@ -149,11 +153,15 @@ def _call(): @pytest.mark.parametrize( "time_o, time_c, time_exp", [ - (TDI([0, 1, 2], "s"), TDI([0, 1, 2], "s"), TDI([0, 1, 2], "s")), ( - TDI([0, 2, 4], "s"), - TDI([1, 3, 5], "s"), - TDI([0, 1, 2, 3, 4, 5], "s"), + pd.to_timedelta([0, 1, 2], "s"), + pd.to_timedelta([0, 1, 2], "s"), + pd.to_timedelta([0, 1, 2], "s"), + ), + ( + pd.to_timedelta([0, 2, 4], "s"), + pd.to_timedelta([1, 3, 5], "s"), + pd.to_timedelta([0, 1, 2, 3, 4, 5], "s"), ), ], ) @@ -326,22 +334,22 @@ def test_from_axis_vectors_exceptions(kwargs, exception_type, test_name): "time, time_ref, time_ref_new, time_exp", [ ( - TDI([1, 2, 3], "D"), + pd.to_timedelta([1, 2, 3], "D"), TS("2020-02-02"), TS("2020-02-01"), - TDI([2, 3, 4], "D"), + pd.to_timedelta([2, 3, 4], "D"), ), ( - TDI([1, 2, 3], "D"), + pd.to_timedelta([1, 2, 3], "D"), TS("2020-02-02"), "2020-02-01", - TDI([2, 3, 4], "D"), + pd.to_timedelta([2, 3, 4], "D"), ), ( - TDI([1, 2, 3], "D"), + pd.to_timedelta([1, 2, 3], "D"), None, "2020-02-01", - TDI([1, 2, 3], "D"), + pd.to_timedelta([1, 2, 3], "D"), ), ], ) @@ -417,42 +425,42 @@ def test_reset_reference_time_exceptions( [ ( # broadcast left TS("2020-02-10"), - TDI([1, 2, 14], "D"), + pd.to_timedelta([1, 2, 14], "D"), TS("2020-02-10"), r_mat_z([0, 0, 0.5]), np.array([[2, 8, 7], [2, 8, 7], [4, 9, 2]]), ), ( # broadcast right TS("2020-02-10"), - TDI([14, 29, 30], "D"), + pd.to_timedelta([14, 29, 30], "D"), TS("2020-02-10"), r_mat_z([0.5, 0.5, 0.5]), np.array([[4, 9, 2], [3, 1, 2], [3, 1, 2]]), ), ( # pure interpolation TS("2020-02-10"), - TDI([11, 14, 17, 20], "D"), + pd.to_timedelta([11, 14, 17, 20], "D"), TS("2020-02-10"), r_mat_z([0.125, 0.5, 0.875, 0.75]), np.array([[2.5, 8.25, 5.75], [4, 9, 2], [1, 3.75, 1.25], [1.5, 1.5, 1.5]]), ), ( # mixed TS("2020-02-10"), - TDI([6, 12, 18, 24, 32], "D"), + pd.to_timedelta([6, 12, 18, 24, 32], "D"), TS("2020-02-10"), r_mat_z([0, 0.25, 1, 0.5, 0.5]), np.array([[2, 8, 7], [3, 8.5, 4.5], [0, 2, 1], [3, 1, 2], [3, 1, 2]]), ), ( # different reference times TS("2020-02-10"), - TDI([8, 14, 20, 26, 34], "D"), + pd.to_timedelta([8, 14, 20, 26, 34], "D"), TS("2020-02-08"), r_mat_z([0, 0.25, 1, 0.5, 0.5]), np.array([[2, 8, 7], [3, 8.5, 4.5], [0, 2, 1], [3, 1, 2], [3, 1, 2]]), ), ( # no reference time None, - TDI([6, 12, 18, 24, 32], "D"), + pd.to_timedelta([6, 12, 18, 24, 32], "D"), None, r_mat_z([0, 0.25, 1, 0.5, 0.5]), np.array([[2, 8, 7], [3, 8.5, 4.5], [0, 2, 1], [3, 1, 2], [3, 1, 2]]), @@ -708,10 +716,22 @@ def test_interp_time_timeseries_as_coords( @pytest.mark.parametrize( "time_ref_lcs, time, time_ref, exception_type, test_name", [ - (TS("2020-02-02"), TDI([1]), None, TypeError, "# mixed ref. times #1"), - (None, TDI([1]), TS("2020-02-02"), TypeError, "# mixed ref. times #2"), + ( + TS("2020-02-02"), + pd.to_timedelta([1]), + None, + TypeError, + "# mixed ref. times #1", + ), + ( + None, + pd.to_timedelta([1]), + TS("2020-02-02"), + TypeError, + "# mixed ref. times #2", + ), (TS("2020-02-02"), "no", TS("2020-02-02"), TypeError, "# wrong type #1"), - (TS("2020-02-02"), TDI([1]), "no", Exception, "# wrong type #2"), + (TS("2020-02-02"), pd.to_timedelta([1]), "no", Exception, "# wrong type #2"), ], ids=get_test_name, ) @@ -764,26 +784,26 @@ def test_interp_time_exceptions( LCS( r_mat_z([0, 0.5, 1]), Q_([1, 4, 2], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), LCS(r_mat_z(0.5), Q_([3, 7, 1], "mm")), r_mat_z([0.5, 1, 1.5]), [[-1, 8, 3], [-1, 8, 3], [-1, 8, 3]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 3 - left system coordinates time dependent LCS( r_mat_y(0.5), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), LCS(r_mat_z(0.5), Q_([3, 7, 1], "mm")), [[[0, -1, 0], [0, 0, 1], [-1, 0, 0]] for _ in range(3)], [[-4, 10, 2], [5, 11, 9], [0, 2, 0]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 4 - right system orientation time dependent @@ -791,12 +811,12 @@ def test_interp_time_exceptions( LCS( r_mat_z([0, 0.5, 1]), Q_([1, 4, 2], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 1, 1.5]), [[4, 11, 3], [-6, 7, 3], [-2, -3, 3]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 5 - right system coordinates time dependent @@ -804,12 +824,12 @@ def test_interp_time_exceptions( LCS( r_mat_z(0.5), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z(1), [[-4, 10, 2], [-3, 1, 9], [-12, 6, 0]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 6 - right system fully time dependent @@ -817,84 +837,84 @@ def test_interp_time_exceptions( LCS( r_mat_z([0, 0.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 1, 1.5]), [[6, 14, 2], [-3, 1, 9], [-8, -4, 0]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 7 - both fully time dependent - same time and reference time LCS( r_mat_z([1, 0, 0]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), LCS( r_mat_z([0, 0.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([1, 0.5, 1]), [[7, 9, 6], [7, 1, 10], [-6, -4, -10]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 8 - both fully time dependent - different time but same reference time LCS( r_mat_z([1.5, 1.0, 0.75]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([2, 4, 6], "D"), + pd.to_timedelta([2, 4, 6], "D"), TS("2020-02-02"), ), LCS( r_mat_z([0.75, 1.25, 0.75]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 0.0, 1.5]), [[-0.5, 0.5, 9.5], [-3.5, 3.5, 5.5], [-10.6568542, -1.242640687, -10]], - TDI([2, 4, 6], "D"), + pd.to_timedelta([2, 4, 6], "D"), TS("2020-02-02"), ), ( # 9 - both fully time dependent - different time and reference time #1 LCS( r_mat_z([1.5, 1.0, 0.75]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-03"), ), LCS( r_mat_z([0.75, 1.25, 0.75]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 0.0, 1.5]), [[-0.5, 0.5, 9.5], [-3.5, 3.5, 5.5], [-10.6568542, -1.242640687, -10]], - TDI([2, 4, 6], "D"), + pd.to_timedelta([2, 4, 6], "D"), TS("2020-02-02"), ), ( # 10 - both fully time dependent - different time and reference time #2 LCS( r_mat_z([1.5, 1.0, 0.75]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([3, 5, 7], "D"), + pd.to_timedelta([3, 5, 7], "D"), TS("2020-02-01"), ), LCS( r_mat_z([0.75, 1.25, 0.75]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 0.0, 1.5]), [[-0.5, 0.5, 9.5], [-3.5, 3.5, 5.5], [-10.6568542, -1.242640687, -10]], - TDI([3, 5, 7], "D"), + pd.to_timedelta([3, 5, 7], "D"), TS("2020-02-01"), ), ], @@ -949,26 +969,26 @@ def test_addition( LCS( r_mat_z([0.5, 1, 1.5]), Q_([-1, 8, 3], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), LCS(r_mat_z(0.5), Q_([3, 7, 1], "mm")), r_mat_z([0, 0.5, 1]), [[1, 4, 2], [1, 4, 2], [1, 4, 2]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 3 - left system coordinates time dependent LCS( [[0, -1, 0], [0, 0, 1], [-1, 0, 0]], Q_([[-4, 10, 2], [5, 11, 9], [0, 2, 0]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), LCS(r_mat_z(0.5), Q_([3, 7, 1], "mm")), r_mat_y([0.5, 0.5, 0.5]), [[3, 7, 1], [4, -2, 8], [-5, 3, -1]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 4 - right system orientation time dependent @@ -976,12 +996,12 @@ def test_addition( LCS( r_mat_z([0, 0.5, 1]), Q_([1, 4, 2], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 0, 1.5]), [[2, 3, -1], [3, -2, -1], [-2, -3, -1]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 5 - right system coordinates time dependent @@ -989,12 +1009,12 @@ def test_addition( LCS( r_mat_z(0.5), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z(0), [[0, 0, 0], [9, 1, -7], [4, -8, 2]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 6 - right system fully time dependent @@ -1002,84 +1022,84 @@ def test_addition( LCS( r_mat_z([0, 0.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.5, 0, 1.5]), [[0, 0, 0], [9, 1, -7], [-8, -4, 2]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 7 - both fully time dependent - same time and reference time LCS( r_mat_z([1, 0.5, 1]), Q_([[7, 9, 6], [7, 1, 10], [-6, -4, -10]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), LCS( r_mat_z([0, 0.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([1, 0, 0]), [[4, 2, 5], [3, -3, 2], [1, 7, -9]], - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), ( # 8 - both fully time dependent - different time but same reference time LCS( r_mat_z([1.5, 1.0, 0.75]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([2, 4, 6], "D"), + pd.to_timedelta([2, 4, 6], "D"), TS("2020-02-02"), ), LCS( r_mat_z([1, 1.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.25, 1.75, 1.75]), [[-3.7426406, 2.9142135, 0.5], [-3.5, 3.742640, -1.5], [-6, -4, -8.0]], - TDI([2, 4, 6], "D"), + pd.to_timedelta([2, 4, 6], "D"), TS("2020-02-02"), ), ( # 9 - both fully time dependent - different time and reference time #1 LCS( r_mat_z([1.5, 1.0, 0.75]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-03"), ), LCS( r_mat_z([1, 1.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.25, 1.75, 1.75]), [[-3.7426406, 2.9142135, 0.5], [-3.5, 3.742640, -1.5], [-6, -4, -8.0]], - TDI([2, 4, 6], "D"), + pd.to_timedelta([2, 4, 6], "D"), TS("2020-02-02"), ), ( # 10 - both fully time dependent - different time and reference time #2 LCS( r_mat_z([1.5, 1.0, 0.75]), Q_([[4, 2, 5], [3, -3, 2], [1, 7, -9]], "mm"), - TDI([3, 5, 7], "D"), + pd.to_timedelta([3, 5, 7], "D"), TS("2020-02-01"), ), LCS( r_mat_z([1, 1.5, 1]), Q_([[3, 7, 1], [4, -2, 8], [-5, 3, -1]], "mm"), - TDI([1, 3, 5], "D"), + pd.to_timedelta([1, 3, 5], "D"), TS("2020-02-02"), ), r_mat_z([0.25, 1.75, 1.75]), [[-3.7426406, 2.9142135, 0.5], [-3.5, 3.742640, -1.5], [-6, -4, -8.0]], - TDI([3, 5, 7], "D"), + pd.to_timedelta([3, 5, 7], "D"), TS("2020-02-01"), ), ], From 2f8e56043f7b941636186f7db409874caeb65fd6 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:33:08 +0100 Subject: [PATCH 09/19] use util func instead of TDI --- weldx/tests/asdf_tests/test_asdf_core.py | 4 ++-- weldx/tests/test_core.py | 4 ++-- weldx/tests/test_utility.py | 10 ++++---- .../tests/transformations/test_cs_manager.py | 24 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/weldx/tests/asdf_tests/test_asdf_core.py b/weldx/tests/asdf_tests/test_asdf_core.py index 67e92bdc9..dadc7c270 100644 --- a/weldx/tests/asdf_tests/test_asdf_core.py +++ b/weldx/tests/asdf_tests/test_asdf_core.py @@ -424,12 +424,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/test_core.py b/weldx/tests/test_core.py index 3ded6821b..b70d111eb 100644 --- a/weldx/tests/test_core.py +++ b/weldx/tests/test_core.py @@ -430,9 +430,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_utility.py b/weldx/tests/test_utility.py index 6658fd3a9..1caa7847a 100644 --- a/weldx/tests/test_utility.py +++ b/weldx/tests/test_utility.py @@ -333,7 +333,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 +352,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": " Date: Wed, 6 Mar 2024 11:34:08 +0100 Subject: [PATCH 10/19] unpin nbval --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e65f52b13..38e0ddeb6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,7 @@ test = [ "pytest >=6", "pytest-cov", "pytest-xdist", - "nbval <0.10", + "nbval", ] vis = [ "weldx_widgets >=0.2", From 4dfab6b4a04424696e7284a5a2fc37733c25276b Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:51:44 +0100 Subject: [PATCH 11/19] updated changelog --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 From b89c52060388382b8c3ef6ce32ae36e70296f2d5 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 11:52:13 +0100 Subject: [PATCH 12/19] treat FutureWarning as error during testing --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 38e0ddeb6..86fdcb5a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,6 +125,7 @@ filterwarnings = [ "ignore::DeprecationWarning:traittypes.*:", "ignore:Passing method to :FutureWarning:xarray.*:", "error::pint.UnitStrippedWarning", + "error::FutureWarning", ] [tool.coverage.run] From 47c7861943e8f92188a282b365935f9504e1f803 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 12:01:26 +0100 Subject: [PATCH 13/19] disabled "treat FutureWarning as error during testing" --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 86fdcb5a9..d152f8ec1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,7 +125,7 @@ filterwarnings = [ "ignore::DeprecationWarning:traittypes.*:", "ignore:Passing method to :FutureWarning:xarray.*:", "error::pint.UnitStrippedWarning", - "error::FutureWarning", + #"error::FutureWarning", # todo: we want to enable this, as it notifies us about upcoming failures due to upstream changes. ] [tool.coverage.run] From 18626b0005246ec6f199e0626daf645cdb5419f2 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 12:32:25 +0100 Subject: [PATCH 14/19] handle all old units --- weldx/tags/time/timedeltaindex.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index d96d180fd..296da28ab 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -8,13 +8,15 @@ __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.""" - # TODO: extend this to other changed units, eventually only seconds - # are relevant to weldx right now, as it was used in the previous schema version. - if "S" in node["freq"]: - node["freq"] = node["freq"][:-1] + "s" + # todo: would it be safer to use a regex here to avoid ambiguity with modern units? + unit = node["freq"][-1] + if unit in PANDAS_OLD_UNIT_SUFFIXES.keys(): + node["freq"] = node["freq"][:-1] + PANDAS_OLD_UNIT_SUFFIXES[unit] class TimedeltaIndexConverter(WeldxConverter): From e758b18e69ca4d1ade0f36e46e7440ca0cf14887 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 12:46:35 +0100 Subject: [PATCH 15/19] handle all old units --- weldx/tags/time/timedeltaindex.py | 1 - 1 file changed, 1 deletion(-) diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index 296da28ab..72b2467f6 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -13,7 +13,6 @@ def _handle_converted_pd_tdi_units(node: TaggedDict): """Convert changed units in Pandas.Datetimeindex to valid values.""" - # todo: would it be safer to use a regex here to avoid ambiguity with modern units? unit = node["freq"][-1] if unit in PANDAS_OLD_UNIT_SUFFIXES.keys(): node["freq"] = node["freq"][:-1] + PANDAS_OLD_UNIT_SUFFIXES[unit] From 89a294d4a3fd5bd5dd69744224dfd67b1891a3c3 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 12:47:00 +0100 Subject: [PATCH 16/19] minor change (asdf warning) --- weldx/asdf/util.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/weldx/asdf/util.py b/weldx/asdf/util.py index c7de94c57..5dcf9ea1a 100644 --- a/weldx/asdf/util.py +++ b/weldx/asdf/util.py @@ -10,9 +10,8 @@ import asdf import pint -from asdf.asdf import SerializationContext from asdf.config import AsdfConfig, get_config -from asdf.extension import Extension +from asdf.extension import Extension, SerializationContext from asdf.tagged import TaggedDict, TaggedList, TaggedString from asdf.util import uri_match as asdf_uri_match from boltons.iterutils import get_path, remap @@ -494,7 +493,7 @@ def from_yaml_tree( def get_weldx_extension(ctx: SerializationContext | AsdfConfig) -> Extension: """Grab the weldx extension from list of current active extensions.""" - if isinstance(ctx, asdf.asdf.SerializationContext): + if isinstance(ctx, asdf.extension.SerializationContext): extensions = ctx.extension_manager.extensions elif isinstance(ctx, asdf.config.AsdfConfig): extensions = ctx.extensions From 33566c18f32f8d5213e2fba3b3fac9060df2535a Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 6 Mar 2024 12:59:54 +0100 Subject: [PATCH 17/19] Revert "minor change (asdf warning)" This reverts commit 89a294d4a3fd5bd5dd69744224dfd67b1891a3c3. --- weldx/asdf/util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weldx/asdf/util.py b/weldx/asdf/util.py index 5dcf9ea1a..c7de94c57 100644 --- a/weldx/asdf/util.py +++ b/weldx/asdf/util.py @@ -10,8 +10,9 @@ import asdf import pint +from asdf.asdf import SerializationContext from asdf.config import AsdfConfig, get_config -from asdf.extension import Extension, SerializationContext +from asdf.extension import Extension from asdf.tagged import TaggedDict, TaggedList, TaggedString from asdf.util import uri_match as asdf_uri_match from boltons.iterutils import get_path, remap @@ -493,7 +494,7 @@ def from_yaml_tree( def get_weldx_extension(ctx: SerializationContext | AsdfConfig) -> Extension: """Grab the weldx extension from list of current active extensions.""" - if isinstance(ctx, asdf.extension.SerializationContext): + if isinstance(ctx, asdf.asdf.SerializationContext): extensions = ctx.extension_manager.extensions elif isinstance(ctx, asdf.config.AsdfConfig): extensions = ctx.extensions From 737c7e4369b34b5bda7007caffcc6c1e94d864f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Wed, 6 Mar 2024 20:31:16 +0100 Subject: [PATCH 18/19] pandas >=1.5 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d152f8ec1..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", From 2e6c519cd31a86b51bf9dad3172b2a40bab217ac Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 12 Mar 2024 08:55:33 +0100 Subject: [PATCH 19/19] Update weldx/tags/time/timedeltaindex.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Çağtay Fabry --- weldx/tags/time/timedeltaindex.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/weldx/tags/time/timedeltaindex.py b/weldx/tags/time/timedeltaindex.py index 72b2467f6..b0aeac6eb 100644 --- a/weldx/tags/time/timedeltaindex.py +++ b/weldx/tags/time/timedeltaindex.py @@ -13,9 +13,8 @@ def _handle_converted_pd_tdi_units(node: TaggedDict): """Convert changed units in Pandas.Datetimeindex to valid values.""" - unit = node["freq"][-1] - if unit in PANDAS_OLD_UNIT_SUFFIXES.keys(): - node["freq"] = node["freq"][:-1] + PANDAS_OLD_UNIT_SUFFIXES[unit] + for suf in PANDAS_OLD_UNIT_SUFFIXES: + node["freq"] = node["freq"].replace(suf, PANDAS_OLD_UNIT_SUFFIXES[suf]) class TimedeltaIndexConverter(WeldxConverter):