Skip to content

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

Closed
cdkang opened this issue Dec 24, 2021 · 8 comments
Closed

QST: mm.Blocks and link streets error #324

cdkang opened this issue Dec 24, 2021 · 8 comments
Labels
question Further information is requested

Comments

@cdkang
Copy link

cdkang commented Dec 24, 2021

Hello,

I have tried mm.Blocks as below. But I face the error message. Could you let me know how to solve this issue?

blocks = mm.Blocks(tessellation, edges=extended, buildings=buildings, id_name='bID', unique_id='uID')
blocks_df = blocks.blocks  # get blocks df
buildings['bID'] = blocks.buildings_id.values  # get block ID
tessellation['bID'] = blocks.tessellation_id.values  # get block ID

ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat

Also, I have got the similar error when I did "link streets" as below.

streets["nID"] = range(len(streets))
buildings['nID'] = mm.get_network_id(buildings, streets, 'nID', min_size=300, verbose=False)
tessellation = tessellation.merge(buildings[['uID', 'nID']], on='uID', how='left')

ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat
@cdkang cdkang changed the title QST: mm.Blocks error QST: mm.Blocks and link streets error Dec 24, 2021
@martinfleis
Copy link
Member

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).

@cdkang
Copy link
Author

cdkang commented Dec 25, 2021

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

@cdkang
Copy link
Author

cdkang commented Dec 25, 2021

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

@martinfleis
Copy link
Member

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.

@cdkang
Copy link
Author

cdkang commented Jan 8, 2022

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
Split features : 229
Overlapping features: 77

@martinfleis
Copy link
Member

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.

@cdkang
Copy link
Author

cdkang commented Jan 10, 2022

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.

@martinfleis
Copy link
Member

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?

@martinfleis martinfleis added the question Further information is requested label Jan 10, 2022
@pysal pysal locked and limited conversation to collaborators Jan 10, 2022
@martinfleis martinfleis converted this issue into discussion #339 Jan 10, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants