Skip to content

Commit

Permalink
fix: access sr as attr, not dict
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdadams committed Oct 8, 2024
1 parent cc5ca85 commit 05bd82e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/palletjack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ def sedf_to_gdf(dataframe):

gdf = gpd.GeoDataFrame(dataframe, geometry=dataframe.spatial.name)
try:
gdf.set_crs(dataframe.spatial.sr["latestWkid"], inplace=True)
gdf.set_crs(dataframe.spatial.sr.latestWkid, inplace=True)
except AttributeError:
gdf.set_crs(dataframe.spatial.sr["wkid"], inplace=True)
gdf.set_crs(dataframe.spatial.sr.wkid, inplace=True)

return gdf

Expand Down
13 changes: 9 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from pathlib import Path

import numpy as np
import palletjack
import pandas as pd
import pyogrio
import pytest
from arcgis import geometry
from arcgis.features import FeatureLayer, Table
from pandas import testing as tm

import palletjack


@pytest.fixture(scope="module") #: only call this once per module
def iris():
Expand Down Expand Up @@ -1833,15 +1834,19 @@ def test_chunker(self):
class TestSEDFtoGDF:
def test_sedf_to_gdf_uses_wkid_when_missing_latestwkid(self, mocker):
gdf_mock = mocker.patch("palletjack.utils.gpd.GeoDataFrame").return_value
df_attrs = {"spatial.sr": {"wkid": "foo"}}
df_mock = mocker.Mock(**df_attrs)

df_mock = mocker.Mock()
df_mock.spatial.sr = mocker.Mock(spec=palletjack.utils.arcgis.geometry.SpatialReference)
df_mock.spatial.sr.wkid = "foo"

palletjack.utils.sedf_to_gdf(df_mock)

gdf_mock.set_crs.assert_called_with("foo", inplace=True)

def test_sedf_to_gdf_uses_sedf_geometry_column(self, mocker):
mock_sedf = mocker.Mock(**{"spatial.name": "FOOSHAPE", "spatial.sr": {"wkid": "foo"}})
mock_sedf = mocker.Mock(**{"spatial.name": "FOOSHAPE"}) # , "spatial.sr": {"wkid": "foo"}})
mock_sedf.spatial.sr = mocker.Mock(spec=palletjack.utils.arcgis.geometry.SpatialReference)
mock_sedf.spatial.sr.wkid = "foo"
gpd_mock = mocker.patch("palletjack.utils.gpd.GeoDataFrame")

palletjack.utils.sedf_to_gdf(mock_sedf)
Expand Down

0 comments on commit 05bd82e

Please sign in to comment.