DOC/TST: use scipy-doctest, update examples with complete imports#2200
DOC/TST: use scipy-doctest, update examples with complete imports#2200jorisvandenbossche merged 3 commits intoshapely:mainfrom
Conversation
There was a problem hiding this comment.
@mwtoews obscuring the real type of values in the doctest might be a little misleading, though? Showing that a value is a Python int when it really is a numpy typed object could trip up somebody. So maybe we use scipy-doctest, but be pedantic about the values?
|
It's certainly a trade-off, but the benefit of keeping the output as it is shown now in the docstrings (and so adopting scipy-doctest to be able to keep doing that also when updating numpy > 2) is that it gives less visual clutter in the example and focuses more on the message to show to the user. If we show an example like: the main message is that it returns False for a XY point. If this shows It's like putting a |
sgillies
left a comment
There was a problem hiding this comment.
Okay, I'm convinced about relaxing the type check.
Pull Request Test Coverage Report for Build 13386052724Details
💛 - Coveralls |
|
If/when NumPy changes their docstrings, then I'd be convinced to change it here too. For instance, see numpy.sin where currently Also, I should note that scipy-doctest has an option >>> shapely.get_coordinate_dimension(Point(0, 0))
np.int32(2)but this option still relaxes >>> shapely.get_srid(shapely.set_srid(Point(0, 0), 1234567890))
np.int32(1234567890) |
That also doesn't seem that important to know the SRID is returned as an int32 vs int64? (SRID numbers are typically smaller numbers than the int32 limits) |
c8ecee9 to
afc522c
Compare
shapely/constructive.py
Outdated
| >>> snap(line1, LineString([]), 0.25) | ||
| <LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)> | ||
| >>> shapely.snap(line1, LineString([]), 0.25).wkt # TODO: why is '.wkt' needed? | ||
| 'LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)' |
There was a problem hiding this comment.
Should this todo get resolved first?
jorisvandenbossche
left a comment
There was a problem hiding this comment.
Looks good!
Added some small comments for consistency
|
I am going to merge those small suggestions, so I can merge this PR now to avoid another round of updating an fixing merge conflicts if I continue merging other PRs! |
|
Thanks @mwtoews! |
This switches from using
doctesttoscipy-doctestto run the doctesting. This is the same extension used by NumPy and SciPy.The motivation for this switch is that it allows flexibility of minor floating-point differences in some outputs, and allows legacy NumPy repr formatting, e.g.:
instead of testing against
np.float64(1.0)as with NumPy 2.0+. While this PR keeps the doctest CI job with NumPy 1.26.2, it runs the same locally with newer versions.Most of the changes in this PR are to provide complete examples, and to call module-level ufuncs from the module. The previous version used (e.g.)
get_x(pt)with an implicitfrom shapely import get_x. However, I think it is better to keep the module-level calls likeshapely.get_x(pt). An exception to this rule is the geometry classes (Point, etc.).Other changes are to set conftest.py to the module root
shapely/, and this is inspired directly from NumPy'snumpy/conftest.py. This allows some options for scipy-doctest and fine-tuning filtering warnings in the doctests.