Value error using sjoin with pandas v0.23
See original GitHub issueI use the sjoin
function to add the region name (polygons) to every point within the region. Some points are not in any region, therefore I filter these points and buffer them step by step. So the points layer without intersection becomes smaller and smaller. If there is only one row left I get the following error in pandas v0.23 which I did not get before (pandas < v0.23). Using geopandas v0.3.0.
My call:
new = gpd.sjoin(rest_points, polygons, how='left', op='intersects')
Error message:
ValueError: You are trying to merge on object and int64 columns.
If you wish to proceed you should use pd.concat
class: GeoDataFrame
method: merge(self, *args, **kwargs)
line: result = DataFrame.merge(self, *args, **kwargs)
I do not understand the error and why it happens only with the last point (last row) and only with the newest pandas version. I had a look at “What’s New” but could not find anything.
Full message:
File "virtualenv/lib/python3.5/site-packages/geopandas/tools/sjoin.py", line 140,
in sjoin suffixes=('_%s' % lsuffix, '_%s' % rsuffix))
File "virtualenv/lib/python3.5/site-packages/geopandas/geodataframe.py", line 418,
in merge result = DataFrame.merge(self, *args, **kwargs)
File "virtualenv/lib/python3.5/site-packages/pandas/core/frame.py", line 6379,
in merge copy=copy, indicator=indicator, validate=validate)
File "virtualenv/lib/python3.5/site-packages/pandas/core/reshape/merge.py", line 60,
in mergevalidate=validate)
File "virtualenv/lib/python3.5/site-packages/pandas/core/reshape/merge.py", line 554,
in __init__self._maybe_coerce_merge_keys()
File "virtualenv/lib/python3.5/site-packages/pandas/core/reshape/merge.py", line 980,
in _maybe_coerce_merge_keys
raise ValueError(msg)
ValueError: You are trying to merge on object and int64 columns.
If you wish to proceed you should use pd.concat
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
What's New — pandas 0.23.0 documentation - PyData |
Bug in indexing a datetimelike Index that raised ValueError instead of IndexError (GH18386). Index.to_series() now accepts index and name kwargs (GH18699) ...
Read more >Combining two Series into a DataFrame in pandas
In one instance, it seems to be telling me 'ValueError: The truth value of an array with more than one element is ambiguous....
Read more >Changelog — GeoPandas 0.12.2+0.gefcb367.dirty ...
explore() for recent Matplotlib versions (#2596). Bug fixes: Fix cryptic error message in geopandas.clip() when clipping with an empty geometry (#2589) ...
Read more >Functions - pyjanitor documentation
:returns: A pandas DataFrame with added columns. """ # Note: error checking can pretty much be handled in `add_column` for col_name, values in...
Read more >What's new in 0.24.0 (January 25, 2019) - Pandas 中文
Pandas has gained the ability to hold integer dtypes with missing values. This long requested feature is enabled through the use of extension ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Does anyone have a proposed solution for this? I would say geopandas is basically incompatible with the latest pandas since this bug affects a common core use case.
One approach I can see is to just add a temporary column w/ the right dtype enforced to use for the join. Kinda gross but would get the job done:
I think a fix would be:
Can you check if that solves the issue for you?