Skip to content

Hash/Equality contract violation #1548

Description

@T90REAL

Code Sample, a copy-pastable example if possible

from pyproj import CRS

a = CRS.from_epsg(3857)
b = CRS.from_wkt(a.to_wkt())

print(a == b)          # True
print(hash(a), hash(b))  # hashes differ

Problem description

Two CRS instances that compare equal (a == b) produce different hash values after a round-trip through WKT. Because CRS.__hash__ delegates to self.to_wkt(), and to_wkt() can emit different—but equivalent—representations, the Python hash/equality contract is violated. This breaks dictionaries, sets, and caches keyed by CRS, since lookups may fail or duplicates may be stored.

Expected Output

Objects that compare equal should yield identical hashes. The code sample above should print True twice.

Environment Information

  • Output from: pyproj -v
 pyproj info:
     pyproj: 3.7.2
 PROJ (runtime): 9.5.1
 PROJ (compiled): 9.5.1
   data dir: /home/hdd/PBT-AgentSys/src/envs/pyproj_env/lib/python3.12/site-packages/pyproj/proj_dir/share/proj
 user_data_dir: /home/.local/share/proj
 PROJ DATA (recommended version): 1.20
 PROJ Database: 1.4
 EPSG Database: v11.022 [2024-11-05]
 ESRI Database: ArcGIS Pro 3.4 [2024-11-04]
 IGNF Database: 3.1.0 [2019-05-24]

 System:
     python: 3.12.12 | packaged by Anaconda, Inc. | (main, Oct 21 2025, 20:16:04) [GCC 11.2.0]
 executable: /home/hdd/PBT-AgentSys/src/envs/pyproj_env/bin/python3
    machine: Linux-5.15.0-139-generic-x86_64-with-glibc2.31

 Python deps:
    certifi: 2025.10.5
     Cython: None
 setuptools: None
        pip: 25.0.1

Installation method

pip (inside a virtual environment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugprojBug or issue related to PROJ

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions