ahwillia / affinewarp

An implementation of piecewise linear time warping for multi-dimensional time series alignment
MIT License
162 stars 36 forks source link

densewarp incompatible with Python2 #13

Closed lwimala closed 4 years ago

lwimala commented 4 years ago

Hi Alex!

I just wanted to raise this as a GitHub issue since Python2 is deprecated, but the fix to make the function compatible is pretty trivial.

To highlight the issue I ran into,

I dove into the code and found that in piecewisewarp.py, the function densewarp has this line (Line 557, https://github.com/ahwillia/affinewarp/blob/master/affinewarp/piecewisewarp.py#L557) :

            # fraction of trial complete
            x = t / (T - 1)

In Python2, this line results in integer division which results in x=0 for all indices in T except for the last index (x=1). To fix this, I simply did:

            # fraction of trial complete
            x = float(t) / (T - 1)

This is not an issue in Python 3, as this line does not result in integer division But I just wanted to give you a heads up in case you wanted to make the change to the code since it is forward-compatible with Python3. Thanks!

Best,

Lahiru

ahwillia commented 4 years ago

Thanks! I'm not sure I want to officially support Python 2, since there might be other minor bugs / incompatibilities that I'm unaware of.

ahwillia commented 4 years ago

I added a warning statement for anyone using Python 2, see - https://github.com/ahwillia/affinewarp/commit/95e91958f36fc69042754618d44f0f97f1f91f97