DEPR: Deprecate shape_index() in favor of radii_ratio()#408
DEPR: Deprecate shape_index() in favor of radii_ratio()#408samay2504 wants to merge 2 commits intopysal:mainfrom
Conversation
- shape_index() is identical to radii_ratio() - Added deprecation warning to shape_index() with clear migration path - Updated radii_ratio() docstring to clarify it is also known as Schumm's shape index - Added comprehensive test to verify deprecation warning is raised - Test confirms shape_index() and radii_ratio() produce identical results - Formatted with ruff and black Closes pysal#248
There was a problem hiding this comment.
Pull request overview
This PR deprecates the shape_index() function in favor of radii_ratio() to establish clearer naming that better expresses the metric's mathematical structure, while maintaining full backward compatibility.
Changes:
- Added deprecation warning to
shape_index()that delegates toradii_ratio() - Enhanced
radii_ratio()docstring with mathematical formula, historical context, and cross-reference - Updated test to verify deprecation warning is properly raised and both functions produce identical results
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| esda/shape.py | Added warnings import; deprecated shape_index() with clear migration path; enhanced radii_ratio() docstring with formula and "See Also" section |
| esda/tests/test_shape.py | Added warnings import; updated test_shape_index() to verify deprecation warning and equivalence with radii_ratio() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| Also known as Schumm's shape index (Schumm (1956) in MacEachren 1985). | ||
|
|
||
| The ratio of the radius of the equi-areal circle to the radius of the MBC |
There was a problem hiding this comment.
Missing period at the end of the description sentence. The line should end with a period for consistency with other docstrings in the module.
| The ratio of the radius of the equi-areal circle to the radius of the MBC | |
| The ratio of the radius of the equi-areal circle to the radius of the MBC. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #408 +/- ##
=====================================
Coverage 82.7% 82.7%
=====================================
Files 27 27
Lines 3829 3830 +1
=====================================
+ Hits 3166 3167 +1
Misses 663 663
🚀 New features to boost your workflow:
|
esda/tests/test_shape.py
Outdated
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| observed = esda.shape.shape_index(shape) | ||
|
|
||
| # Check that deprecation warning was raised | ||
| assert len(w) == 1 | ||
| assert issubclass(w[0].category, DeprecationWarning) | ||
| assert "deprecated" in str(w[0].message).lower() | ||
| assert "radii_ratio" in str(w[0].message) |
There was a problem hiding this comment.
Just use pytest.warns and check the message match. This is unnecessary.
| # Check that result matches radii_ratio | ||
| expected = esda.shape.radii_ratio(shape) | ||
| testing.assert_allclose(observed, expected, atol=ATOL) |
There was a problem hiding this comment.
Keep the original test here. You are deprecating stuff, you should ensure that original tests pass.
testing.assert_allclose(observed, 0.659366, atol=ATOL)
esda/shape.py
Outdated
| """ | ||
| Schumm’s shape index (Schumm (1956) in MacEachren 1985) | ||
| .. deprecated:: 2.5.0 | ||
| ``shape_index`` is deprecated and will be removed in version 3.0.0. |
There was a problem hiding this comment.
| ``shape_index`` is deprecated and will be removed in version 3.0.0. | |
| ``shape_index`` is deprecated and will be removed in future. |
Might be before 3.0.0.
esda/shape.py
Outdated
| Schumm’s shape index (Schumm (1956) in MacEachren 1985) | ||
| .. deprecated:: 2.5.0 | ||
| ``shape_index`` is deprecated and will be removed in version 3.0.0. | ||
| Use ``radii_ratio`` instead, which computes the same Schumm's shape index |
There was a problem hiding this comment.
| Use ``radii_ratio`` instead, which computes the same Schumm's shape index | |
| Use :func:`radii_ratio` instead, which computes the same Schumm's shape index |
This shall give a link.
esda/shape.py
Outdated
| ga = _cast(collection) | ||
| return numpy.sqrt(shapely.area(ga) / numpy.pi) / shapely.minimum_bounding_radius(ga) | ||
| warnings.warn( | ||
| "shape_index is deprecated and will be removed in version 3.0.0. " |
There was a problem hiding this comment.
| "shape_index is deprecated and will be removed in version 3.0.0. " | |
| "shape_index is deprecated and will be removed in future. " |
… deprecation messages to 'future', add func cross-references
|
@martinfleis I have applied the changes you have asked for so please review them and tell me if you want anything else modified. |
fixes #248.
Solution
Deprecated
shape_index()in favor ofradii_ratio()with:radii_ratiobetter expresses the metric's mathematical structureradii_ratio()docstring to note it's also known as Schumm's shape indexChanges
esda/shape.py:
import warningsat module levelshape_index()now emitsDeprecationWarningand delegates toradii_ratio()radii_ratio()docstring with mathematical formula and historical notesesda/tests/test_shape.py:
test_shape_index()to verify deprecation warning is properly raisedwarningsmoduleTesting
Both
test_shape_index()andtest_radii_ratio()passDeprecation warning correctly raised with stacklevel=2
No regressions in any shape module tests
Code formatted with ruff and black