Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
CagtayFabry authored Mar 12, 2024
2 parents 17f3057 + ab583be commit 8cdcaf1
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fetch-depth: 0 # Fetch all history for all tags and branches

- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: ./devtools/conda.recipe/build_env.yml
environment-name: build_env
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
fetch-depth: 0 # Fetch all history for all tags and branches

- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: ./doc/rtd_environment.yml
environment-name: rtd
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
setup_requires: 'include'

- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: ./environment.yml
environment-name: weldx
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
setup_requires: 'include'

- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: ./environment.yml
environment-name: weldx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest_asdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
setup_requires: 'include'

- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: ./environment.yml
environment-name: weldx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('./environment.yml') }}

- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: ./environment.yml
environment-name: weldx
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -64,7 +64,7 @@ test = [
"pytest >=6",
"pytest-cov",
"pytest-xdist",
"nbval <0.10",
"nbval",
]
vis = [
"weldx_widgets >=0.2",
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion weldx/schemas/weldx.bam.de/weldx/time/time-0.1.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ examples:
values: !<asdf://weldx.bam.de/weldx/tags/time/datetimeindex-0.1.0>
start: !<asdf://weldx.bam.de/weldx/tags/time/timestamp-0.1.0> '2021-01-01T00:00:00'
end: !<asdf://weldx.bam.de/weldx/tags/time/timestamp-0.1.0> '2021-01-01T00:00:02'
freq: S
freq: s
min: !<asdf://weldx.bam.de/weldx/tags/time/timestamp-0.1.0> '2021-01-01T00:00:00'
max: !<asdf://weldx.bam.de/weldx/tags/time/timestamp-0.1.0> '2021-01-01T00:00:02'
reference_time: !<asdf://weldx.bam.de/weldx/tags/time/timestamp-0.1.0> '2021-01-01T00:00:00'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ examples:
!<asdf://weldx.bam.de/weldx/tags/time/timedeltaindex-0.1.0>
start: !<asdf://weldx.bam.de/weldx/tags/time/timedelta-0.1.0> P0DT0H0M0S
end: !<asdf://weldx.bam.de/weldx/tags/time/timedelta-0.1.0> P0DT0H0M10S
freq: 2S
freq: 2s
min: !<asdf://weldx.bam.de/weldx/tags/time/timedelta-0.1.0> P0DT0H0M0S
max: !<asdf://weldx.bam.de/weldx/tags/time/timedelta-0.1.0> P0DT0H0M10S
-
Expand Down
10 changes: 10 additions & 0 deletions weldx/tags/time/timedeltaindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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"]
)
Expand All @@ -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"]),
Expand Down
4 changes: 2 additions & 2 deletions weldx/tests/asdf_tests/test_asdf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,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"),
)

Expand Down
24 changes: 14 additions & 10 deletions weldx/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,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"
Expand All @@ -252,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,)),
],
Expand Down Expand Up @@ -330,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"])
Expand Down Expand Up @@ -383,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")
Expand Down Expand Up @@ -427,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],
Expand Down
Loading

0 comments on commit 8cdcaf1

Please sign in to comment.