pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
259 stars 78 forks source link

ENH: implement Graph.__repr__ #711

Closed martinfleis closed 3 months ago

martinfleis commented 4 months ago

I quite like when the __repr__ actually says something about the object, so here's a draft of Graph.__repr__. Happy to iterate over if you have ideas what and how should be shown. The info I picked now is very cheap to compute.

In [1]: import numpy as np
   ...: from libpysal import graph
   ...: import geopandas as gpd
   ...: from geodatasets import get_path

In [2]: coords = np.random.random((100_000, 2))

In [5]: delaunay = graph.Graph.build_triangulation(coords)

In [6]: %time r = delaunay.__repr__()
CPU times: user 27 ms, sys: 10.9 ms, total: 37.9 ms
Wall time: 36.9 ms

In [7]: delaunay
Out[7]: 
<Graph of 100000 nodes and 599936 nonzero edges indexed by
 [0, 1, 2, 3, 4, ...]>

In [8]: nybb = gpd.read_file(get_path('nybb')).set_index('BoroName')

In [9]: contig = graph.Graph.build_contiguity(nybb)
   ...: contig
Out[9]: 
<Graph of 5 nodes and 10 nonzero edges indexed by
 ['Staten Island', 'Queens', 'Brooklyn', 'Manhattan', 'Bronx']>

udpated to match the latest formatting

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.0%. Comparing base (bcabdbc) to head (07e3c66). Report is 16 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/libpysal/pull/711/graphs/tree.svg?width=650&height=150&src=pr&token=wgnkG5Rj0J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)](https://app.codecov.io/gh/pysal/libpysal/pull/711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #711 +/- ## ======================================= - Coverage 85.0% 85.0% -0.0% ======================================= Files 141 145 +4 Lines 15203 15381 +178 ======================================= + Hits 12924 13068 +144 - Misses 2279 2313 +34 ``` | [Files](https://app.codecov.io/gh/pysal/libpysal/pull/711?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [libpysal/graph/base.py](https://app.codecov.io/gh/pysal/libpysal/pull/711?src=pr&el=tree&filepath=libpysal%2Fgraph%2Fbase.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvYmFzZS5weQ==) | `97.0% <100.0%> (-0.9%)` | :arrow_down: | | [libpysal/graph/tests/test\_base.py](https://app.codecov.io/gh/pysal/libpysal/pull/711?src=pr&el=tree&filepath=libpysal%2Fgraph%2Ftests%2Ftest_base.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bGlicHlzYWwvZ3JhcGgvdGVzdHMvdGVzdF9iYXNlLnB5) | `100.0% <100.0%> (ø)` | | ... and [5 files with indirect coverage changes](https://app.codecov.io/gh/pysal/libpysal/pull/711/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)