Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Make DTW alignment plot compatible with RangeIndex #1880

Merged
merged 5 commits into from
Jul 11, 2023

Conversation

AhmetZamanis
Copy link
Contributor

Fixes issue #1871 by modifying the DTWAlignment.plot_alignment() method, so it works with both DateTimeIndex & RangeIndex time dimensions.

Summary

Currently, plot_alignment() converts the x-axis coordinates for the alignment lines into DateTime (lines 154-155). The PR modifies this so the x-axis coordinates match the datatype of the series' time dimensions (DateTime or int).

I also replaced np.empty with np.zeros (line 160), as doing x_coords[2::3] = np.nan raises an error (not sure why), but leaving x_coords[2::3] as all zeroes seems to work for RangeIndex time dimensions.

Other Information

I tested this fix on the same series with both DateTime and RangeIndex time dimensions, and they produced the same plots.

Modify the DTWAlignment.plot_alignment() method so it works with both DateTime & RangeIndex time dimensions
@madtoinou madtoinou linked an issue Jul 4, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2023

Codecov Report

Patch coverage: 81.81% and project coverage change: -0.03 ⚠️

Comparison is base (047e695) 93.95% compared to head (0e1dba0) 93.92%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1880      +/-   ##
==========================================
- Coverage   93.95%   93.92%   -0.03%     
==========================================
  Files         125      125              
  Lines       11738    11729       -9     
==========================================
- Hits        11028    11017      -11     
- Misses        710      712       +2     
Impacted Files Coverage Δ
darts/dataprocessing/dtw/_plot.py 77.33% <81.81%> (-1.24%) ⬇️

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AhmetZamanis and thanks a lot for this fix :) 🚀

I only had two minor suggestions.

@@ -151,18 +151,19 @@ def plot_alignment(
time_dim1 = series1._time_dim
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change these to series1.time_dim and series2.time_dim?

Comment on lines 160 to 166
x_coords = np.zeros(n * 3, dtype=xa1[time_dim1].dtype)
y_coords = np.empty(n * 3, dtype=np.float64)

x_coords[0::3] = x_coords1
x_coords[1::3] = x_coords2
x_coords[2::3] = np.datetime64("NaT")
if x_coords.dtype == "datetime64[s]":
x_coords[2::3] = np.datetime64("NaT")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change lines 160-166 to the following?
The reason why x_coords[2::3] = np.nan failed for integer indexed series, is because only float arrays (not integer) allow NaNs

    if series1.has_datetime_index:
        x_dtype = xa1[time_dim1].dtype
        x_nan = np.datetime64("NaT")
    else:
        x_dtype = np.float64
        x_nan = np.nan
    
    x_coords = np.empty(n * 3, dtype=x_dtype)
    y_coords = np.empty(n * 3, dtype=np.float64)

    x_coords[0::3] = x_coords1
    x_coords[1::3] = x_coords2
    x_coords[2::3] = x_nan

darts/dataprocessing/dtw/_plot.py Show resolved Hide resolved
@AhmetZamanis
Copy link
Contributor Author

Thanks @dennisbader, I made the changes you required. Let me know if there is any issue.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks a lot for your contribution @AhmetZamanis 🚀 💯

@dennisbader dennisbader added this to In review in darts via automation Jul 11, 2023
@dennisbader dennisbader merged commit 4ded99a into unit8co:master Jul 11, 2023
9 checks passed
darts automation moved this from In review to Done Jul 11, 2023
@AhmetZamanis AhmetZamanis deleted the fix/dtw-plot-alignment branch July 11, 2023 13:37
@dennisbader dennisbader moved this from Done to Released in darts Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
darts
Released
Development

Successfully merging this pull request may close these issues.

DTW alignment plot does not seem to work properly [BUG]
3 participants