Replace deprecated pandas and geopandas API calls#80
Conversation
- Replace `delim_whitespace=True` with `sep=r'\s+'` in pd.read_csv calls (deprecated since pandas 2.2) - Replace `op='within'` with `predicate='within'` in gpd.sjoin (deprecated since geopandas 0.10) - Replace DataFrame.append() with pd.concat() (removed in pandas 2.0) Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
@dbetchkal please also review this PR as it makes the code future proof. |
|
Good call. The replacements are all 1:1 behavioral equivalents (sjoin predicate= instead of op=, concat instead of append, etc) but having tests to confirm that is worth doing. I'll push those. |
Unit tests covering the three API migrations: - pd.read_csv sep=r'\s+' replacing delim_whitespace=True - pd.concat replacing DataFrame.append - gpd.sjoin predicate= replacing op= Each test class uses self-contained data and verifies the new calls produce correct results matching the old behavior. Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
There was a problem hiding this comment.
Apologies as I was unclear in my previous comment. Ideally, we would test the behavior that utilizes this pandas/geopandas functionality rather than the library functionality itself. I realize that the behavior in the active space generation may be complex and difficult to unit test cleanly in its current state though.
For the sjoin and ConcatReplacesAppend tests, I'm not sure how much additional value those provide in their current form.
If what I'm getting at is unclear, let me know and happy to explain more or call briefly.
There was a problem hiding this comment.
That makes sense. You're right that testing sjoin and concat in isolation doesn't add much beyond confirming pandas works. I'll drop the ConcatReplacesAppend and sjoin-specific tests and replace them with something that exercises the actual downstream behavior (e.g. a small GeoDataFrame going through the spatial join logic in helpers or the track merging path). Will push an update.
Fixes a few deprecated API calls that currently emit warnings and will break on newer versions of pandas and geopandas.
Changes:
delim_whitespace=Truereplaced withsep=r'\s+'inpd.read_csv()calls. Thedelim_whitespaceparameter was deprecated in pandas 2.2 and will be removed in a future version. Both inactive_space_generator.pyand the legacyactive_space_utils.py.op='within'replaced withpredicate='within'ingpd.sjoin(). Theopparameter was renamed topredicatein geopandas 0.10 and has been raising deprecation warnings since.DataFrame.append()replaced withpd.concat()ingenerate_active_space_mesh.py. The.append()method was removed entirely in pandas 2.0.These are all drop-in replacements with identical behavior, just using the current API names. Should help when upgrading to newer pandas/geopandas releases down the road.