question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

equals is True but almost_equals is False

See original GitHub issue

Expected behavior and actual behavior.

almost_equals should return True, if equals is True.

Steps to reproduce the problem.

import numpy as np
from shapely.geometry import Polygon, box

coords = np.array(
       [[ 577., 1250.],
       [ 593., 1325.],
       [2447., 1002.],
       [2447.,  945.]], dtype=np.float32
)

p = Polygon(coords)
rect = Polygon.from_bounds(*p.bounds)
rect2 = box(*p.bounds)

print(rect.equals(rect2))
print(rect.almost_equals(rect2))

Operating system

Ubuntu Linux 16

Shapely version and provenance

1.7.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
jorisvandenbosschecommented, Apr 5, 2020

I would be +1 on deprecating almost_equals. (note that it’s equals_exact that has a tolerance argument, almost_equals has a “decimals” argument which gets translated to a tolerance)

I was looking at JTS some time ago (https://docs.geotools.org/latest/userguide/library/jts/equals.html) for possible inspiration, and they have a “equalsTopo” (for a more explicit name for “equals”), and a “equalsNorm” (which does an exact equals but automatically normalizes the geometries first)

I think certainly the normalization (either as separate function as JTS, or as option in equals_exact) would be useful (I think it will be more accessible than a separate normalization function).

2reactions
sgilliescommented, Apr 4, 2020

@dashesy we could deprecate almost_equals (confusing name, I agree) and move its tolerance argument to equals_exact (default tolerance of 0). Would that improve the situation from your perspective?

Read more comments on GitHub >

github_iconTop Results From Across the Web

equals is True but almost_equals is False · Issue #889 - GitHub
But the almost_equals method, on the other hand, checks if two objects are structurally equal. This method uses exact coordinate equality, which ...
Read more >
Pandas df.equals() returning False on identical dataframes?
Show activity on this post. So, df. equals will return True only when the elements have same values and the dtypes is also...
Read more >
Equality comparisons and sameness - JavaScript | MDN
If the values have the same type, are not numbers, and have the same value, they're considered equal. Finally, if both values are...
Read more >
Equals sign - Wikipedia
The expression 0 == false is true, but 0 == undefined is false, even though both sides of the == act the same...
Read more >
pandas.DataFrame.equals — pandas 1.5.2 documentation
Compare two Series objects of the same length and return a Series where each element is True if the element in each Series...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found