import hashlib, json, math, sys
from pathlib import Path
import geopandas as gpd
import folium, pyproj
out=Path(__file__).resolve().parent
points=gpd.GeoDataFrame({'Site':['Fictional A','Fictional B']},geometry=gpd.points_from_xy([111319.490793,222638.981587],[0,111325.142866]),crs='EPSG:3857')
geographic=points.to_crs('EPSG:4326')
actual=[[p.x,p.y] for p in geographic.geometry]; expected=[[1,0],[2,1]]
assert all(abs(a-e)<1e-8 for row,exp in zip(actual,expected) for a,e in zip(row,exp))
wrong=points.set_crs('EPSG:4326',allow_override=True)
assert wrong.geometry.x.iloc[0]==points.geometry.x.iloc[0] and geographic.geometry.x.iloc[0]!=points.geometry.x.iloc[0]
m=geographic.explore(tiles=None,tooltip=['Site'],popup=['Site'],marker_type='circle_marker',marker_kwds={'radius':9},height=420,control_scale=False)
m.save(str(out/'geopandas-explore-coordinate-reference.native.html'))
receipt={'python':sys.version,'geopandas':gpd.__version__,'folium':folium.__version__,'pyproj':pyproj.__version__,'fictional':True,'sourceCRS':points.crs.to_string(),'outputCRS':geographic.crs.to_string(),'source':[[p.x,p.y] for p in points.geometry],'expected':expected,'actual':actual,'tolerance':1e-8,'relabeledUntransformed':[[p.x,p.y] for p in wrong.geometry],'geojson':json.loads(geographic.to_json()),'mapVariable':m.get_name(),'sha256':hashlib.sha256((out/'geopandas-explore-coordinate-reference.native.html').read_bytes()).hexdigest()}
(out/'geopandas-native-execution.json').write_text(json.dumps(receipt,indent=2),encoding='utf8');print(json.dumps(receipt))
