miniufo/besttracks

minor error encountered in duration()

tions-icu opened this issue · 7 comments

Thank you for your work. It looks really nice.

However, as I try out the guidance code, minor error was encountered with the line 84 of core.py as I run parse_TCs().

return duration.astype('timedelta64[h]').astype(int) / 24.0
Error message: AttributeError: 'Timedelta' object has no attribute 'astype'

I wish to confirm if this line is only intended to return the number of days.

I appear to have get around this error by replacing the line with the following

return duration.days

I wish to see if this is what is being intended. If so, it might be advisable to update the code on the repository.

Hi, you are right, this is converted to the number of days. However, the code works well on my computer. Not sure what's go wrong.

image

fwiw;
the same error occurs on the machine:

Mac M1 Darwin 21.4.0 Darwin Kernel Version 21.4.0
Python 3.8.9
numpy 1.24.1 py39hefdcf20_0 conda-forge

this issue is mentioned with suggested solution on stack overflow:

timedelta-object-cannot-be-converted-with-astype

here is a 'git diff' showing a solution:

(btk) bash-3.2$ git diff besttracks/core.py
diff --git a/besttracks/core.py b/besttracks/core.py
index 876c4ae..cc2e43a 100644
--- a/besttracks/core.py
+++ b/besttracks/core.py
@@ -133,7 +133,7 @@ class Particle(object):
Duration of this particle in unit of day
"""
duration = np.ptp(self.records['TIME'])

  •    return duration.astype('timedelta64[h]').astype(int) / 24.0
    
  •    return pd.to_timedelta([duration]).astype('timedelta64[h]')[0] / 24.0
    

    def resample(self, *args, **kwargs):

Hi @schaferk, thank you very much. This should be a more robust solution. Could you please send a PR and I would like to include your contribution to the package.

attempted push with branch for (proposed) PR unsuccessful:

_ERROR: Permission to miniufo/besttracks.git denied to schaferk.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists._

Ooops, that is strange. The repo does exist. Have you forked the whole repo, clone it to your local machine from your account, do the modification, and then send the PR?

Hi @schaferk can we close this now?