-
Notifications
You must be signed in to change notification settings - Fork 58
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QST: mm.Blocks and link streets error #324
Comments
Thanks for the report. Can you provide full traceback (full error message)? I don't know where does this ValueError come from. If you can prepare a minimal reproducible example, that would also help (you can check this guide - https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports). |
Merry Christmas and Happy New Year The below is the full taceback for mm.Blocks error. ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_16632/682547552.py in <module>
----> 1 blocks = mm.Blocks(tessellation, edges=extended, buildings=buildings, id_name='bID', unique_id='uID')
2 blocks_df = blocks.blocks # get blocks df
3 buildings['bID'] = blocks.buildings_id.values # get block ID
4 tessellation['bID'] = blocks.tessellation_id.values # get block ID
C:\anaconda\envs\geo\lib\site-packages\momepy\elements.py in __init__(self, tessellation, edges, buildings, id_name, unique_id, **kwargs)
658 )
659
--> 660 cells_copy = tessellation[[unique_id, tessellation.geometry.name]].merge(
661 centroids_tempID[[unique_id, "component"]], on=unique_id, how="left"
662 )
C:\anaconda\envs\geo\lib\site-packages\geopandas\geodataframe.py in merge(self, *args, **kwargs)
1376
1377 """
-> 1378 result = DataFrame.merge(self, *args, **kwargs)
1379 geo_col = self._geometry_column_name
1380 if isinstance(result, DataFrame) and geo_col in result:
C:\anaconda\envs\geo\lib\site-packages\pandas\core\frame.py in merge(self, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
9189 from pandas.core.reshape.merge import merge
9190
-> 9191 return merge(
9192 self,
9193 right,
C:\anaconda\envs\geo\lib\site-packages\pandas\core\reshape\merge.py in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
103 validate: str | None = None,
104 ) -> DataFrame:
--> 105 op = _MergeOperation(
106 left,
107 right,
C:\anaconda\envs\geo\lib\site-packages\pandas\core\reshape\merge.py in __init__(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, copy, indicator, validate)
700 # validate the merge keys dtypes. We may need to coerce
701 # to avoid incompatible dtypes
--> 702 self._maybe_coerce_merge_keys()
703
704 # If argument passed to validate,
C:\anaconda\envs\geo\lib\site-packages\pandas\core\reshape\merge.py in _maybe_coerce_merge_keys(self)
1253 inferred_right in string_types and inferred_left not in string_types
1254 ):
-> 1255 raise ValueError(msg)
1256
1257 # datetimelikes must match exactly
ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat |
I have change type of uID and tried mm.Blocks. But the error was appeared as below. ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_5416/682547552.py in <module>
----> 1 blocks = mm.Blocks(tessellation, edges=extended, buildings=buildings, id_name='bID', unique_id='uID')
2 blocks_df = blocks.blocks # get blocks df
3 buildings['bID'] = blocks.buildings_id.values # get block ID
4 tessellation['bID'] = blocks.tessellation_id.values # get block ID
C:\anaconda\envs\geo\lib\site-packages\momepy\elements.py in __init__(self, tessellation, edges, buildings, id_name, unique_id, **kwargs)
687 )
688 self.buildings_id = buildings_m[id_name]
--> 689 self.buildings_id.index = self.buildings.index
690
691 cells_m = tessellation[[unique_id]].merge(
C:\anaconda\envs\geo\lib\site-packages\pandas\core\generic.py in __setattr__(self, name, value)
5498 try:
5499 object.__getattribute__(self, name)
-> 5500 return object.__setattr__(self, name, value)
5501 except AttributeError:
5502 pass
C:\anaconda\envs\geo\lib\site-packages\pandas\_libs\properties.pyx in pandas._libs.properties.AxisProperty.__set__()
C:\anaconda\envs\geo\lib\site-packages\pandas\core\series.py in _set_axis(self, axis, labels, fastpath)
557 if not fastpath:
558 # The ensure_index call above ensures we have an Index object
--> 559 self._mgr.set_axis(axis, labels)
560
561 # ndarray compatibility
C:\anaconda\envs\geo\lib\site-packages\pandas\core\internals\managers.py in set_axis(self, axis, new_labels)
214 def set_axis(self, axis: int, new_labels: Index) -> None:
215 # Caller is responsible for ensuring we have an Index object.
--> 216 self._validate_set_axis(axis, new_labels)
217 self.axes[axis] = new_labels
218
C:\anaconda\envs\geo\lib\site-packages\pandas\core\internals\base.py in _validate_set_axis(self, axis, new_labels)
55
56 elif new_len != old_len:
---> 57 raise ValueError(
58 f"Length mismatch: Expected axis has {old_len} elements, new "
59 f"values have {new_len} elements"
ValueError: Length mismatch: Expected axis has 586629 elements, new values have 581254 elements |
I think that this may be caused by a similar issue as reported in #326. The function now expects a 1:1 match between buildings and tessellation but that is likely something we may want to relax a bit. |
Hello, I think the Block making error came from the below. Let me know how to clean my building shape file that already preprocess function of momepy. Due to the length mismatch, I can not make Block file with momepy. Collapsed features : 0 |
Would you be able to provide a reproducible example? We may be able to fix the issue in the code but right now I am not able to reproduce it. Check this post on how to do that optimally https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports. |
Thank you so much for your help. I would like to email my shape files to your email. Please let me know your email that you can get my data. |
Have you tried crafting the example following the blog post? I can as well debug the issue on your data but considering its size, I'd rather not to. If you are not able to create the example, can you at least send only a small subset of your data that is also causing this issue? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hello,
I have tried mm.Blocks as below. But I face the error message. Could you let me know how to solve this issue?
Also, I have got the similar error when I did "link streets" as below.
The text was updated successfully, but these errors were encountered: