Skip to content
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

ENH: implement Graph.__repr__ #711

Merged
merged 3 commits into from
Jun 7, 2024
Merged

ENH: implement Graph.__repr__ #711

merged 3 commits into from
Jun 7, 2024

Conversation

martinfleis
Copy link
Member

@martinfleis martinfleis commented May 27, 2024

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

Copy link

codecov bot commented May 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

@@           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 Coverage Δ
libpysal/graph/base.py 97.0% <100.0%> (-0.9%) ⬇️
libpysal/graph/tests/test_base.py 100.0% <100.0%> (ø)

... and 5 files with indirect coverage changes

libpysal/graph/base.py Outdated Show resolved Hide resolved
@martinfleis martinfleis merged commit f028d26 into pysal:main Jun 7, 2024
11 checks passed
@martinfleis martinfleis deleted the repr branch June 7, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants