Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hongyeehh
Copy link
Member

closes #644

The issue is raised due to a recent update in the GeoDataFrame function _geodataframe_constructor_with_fallback() (see here), where instead of the hardcoded GeoDataFrame (line 54), a class instance cls is passed to the function and implicitly initialized (line 2026). This means we cannot pass self, but instead need to explicitly pass and call GeoDataFrame to prevent initializing a trackintel class. The latter will raise an error because the geometry link is only assigned at the very end of the GeoDataFrame._constructor_from_mgr() function (see here).

The PR also contains a minor fix to explicitly convert sp into GeoDataFrame before processing, otherwise the validate function will be called multiple times.

@hongyeehh hongyeehh requested a review from NinaWie June 4, 2025 15:32
Copy link
Member

@NinaWie NinaWie left a comment

Choose a reason for hiding this comment

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

Amazing that you found this! Your argument makes sense to me and this is a proper fix (you won over ChatGPT ;) )
I'm slightly confused about the sp = gpd.GeoDataFrame(staypoints.copy()) - I don't understand how this additional casting can avoid calling validate twice, but I guess you tested this. However, it seems like something that would also happen for positionfixes / locations etc in other parts of the code.

@hongyeehh
Copy link
Member Author

Amazing that you found this! Your argument makes sense to me and this is a proper fix (you won over ChatGPT ;) ) I'm slightly confused about the sp = gpd.GeoDataFrame(staypoints.copy()) - I don't understand how this additional casting can avoid calling validate twice, but I guess you tested this. However, it seems like something that would also happen for positionfixes / locations etc in other parts of the code.

Thanks for the check! The casting is for avoiding errors for later processing functions, e.g. I found that validate will be called when calling dissolve function I.e. line 145, which will raise an error as the intermediate data frames does not necessary fulfill our sp definition (missing columns for example). I thus think casting to geodataframe makes sense, but have to admit we need to check why certain functions will trigger validate while others don’t.

@NinaWie
Copy link
Member

NinaWie commented Jun 4, 2025

Okay makes sense. Yes it's a bit mysterious right now why validate is triggered, but we can look at this separately.

@hongyeehh hongyeehh merged commit 8190487 into mie-lab:master Jun 5, 2025
9 checks passed
@hongyeehh hongyeehh deleted the fix-tests branch June 5, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema validation in model constructors breaks standard GeoPandas >=1.1.0 operations (e.g., sort, merge_asof, sjoin)

2 participants