triskadecaepyon / pyworkout-toolkit

Python tools to process workout data and telemetry for metrics and machine learning
BSD 3-Clause "New" or "Revised" License
19 stars 4 forks source link

Error in reading in "np.str" #13

Open mckennahuse opened 5 days ago

mckennahuse commented 5 days ago

When I attempted to parse my TCX file, the error message below was generated. This appears to be something that can easily be fixed, just adjusting how certain parts of the file are cast to str.


AttributeError Traceback (most recent call last) Cell In[33], line 2 1 workout_data = tcxtools.TCXPandas(jsonfile) # Create the Class Object ----> 2 workout_data.parse()

File ~\anaconda3\Lib\site-packages\pyworkout\parsers\tcxtools.py:42, in TCXPandas.parse(self) 40 self.activity = self.tcx.getroot().Activities.Activity 41 # TODO: Maybe make this privite to the class ---> 42 lap_data = self._traverselaps() 43 mid_frame = [] 44 for laps in lap_data:

File ~\anaconda3\Lib\site-packages\pyworkout\parsers\tcxtools.py:65, in TCXPandas._traverselaps(self) 63 lap_totals = [] 64 for laps in self.activity.Lap.getnext(): ---> 65 laps_list = self._traversetracks(laps) 66 lap_totals.append(laps_list) 67 return lap_totals

File ~\anaconda3\Lib\site-packages\pyworkout\parsers\tcxtools.py:71, in TCXPandas._traversetracks(self, lap_items) 70 def _traversetracks(self, lap_items): ---> 71 trackingpoints = self._traversetrackingpoints(lap_items.Track) 72 return trackingpoints

File ~\anaconda3\Lib\site-packages\pyworkout\parsers\tcxtools.py:79, in TCXPandas._traversetrackingpoints(self, track_items) 76 for trackingpoints in track_items.Trackpoint.getnext(): 77 # TODO: Write sport specific checks to prevent extra features 78 return_dict = {} ---> 79 return_dict['time'] = np.str(trackingpoints.Time) 80 try: 81 return_dict['altitude'] = np.float(trackingpoints.AltitudeMeters)

File ~\anaconda3\Lib\site-packages\numpy__init.py:324, in getattr(attr) 319 warnings.warn( 320 f"In the future np.{attr} will be defined as the " 321 "corresponding NumPy scalar.", FutureWarning, stacklevel=2) 323 if attr in former_attrs: --> 324 raise AttributeError(former_attrs__[attr]) 326 if attr == 'testing': 327 import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'str'. np.str was a deprecated alias for the builtin str. To avoid this error in existing code, use str by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.str_ here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

mckennahuse commented 5 days ago

Upon looking into this further at the source file - it appears that the version on github has been updated. I'm not sure why the version that was installed (with pip install pyworkout-toolkit) was an older version of the package. Therefore I'm not sure whether the issue is in how the instructions ask you to install the package, or if there is something else that needs to be updated to ensure that the latest version is downloaded. Anway, thanks for taking a look at the issue, I'll be able to resolve the issue in the meantime by updating my files, but am wondering what the issue is (if it's not just me!)

triskadecaepyon commented 5 days ago

Hi @mckennahuse , no worries--you've reminded me that my pip version has been less monitored and updated than the conda version! I'll need to take a look to see if I broke the CI or if I need to get the CI working for that.

Do you happen to know what type of workout file was used (as in Run, Bike, Hike, et al.)?

The combination of the LXML standard behavior and the deprecation of functions in the NumPy or Pandas always make for some interesting parsing errors when the versions update! I'll keep the issue open until we can verify it is solved on TCX file variant.

mckennahuse commented 5 days ago

Hi @triskadecaepyon! Thanks so much for responding so quickly!! I was working on a bike workout file.

I was able to replace the file with the more current version, but still had to make some changes to the items labeled as "np.float" to just "float". I did check, I'm using numpy version 1.26.4. Now having checked and seeing that pyworkout uses numpy 1.11... that reasonably explains the errors coming up, ha. Now seeing that even my local numpy is out of date (latest version is 2.1.2), I'll have to check and make sure that these changes also work with the latest version.

Thanks so much for looking into this!

EDIT/PS: I did update numpy and check whether anything other than my changes (changing np.float --> float ) were sufficient to run pyworkout, no additional issues came up after updating numpy.