ssb-sgis 1.1.7__py3-none-any.whl → 1.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -824,11 +824,14 @@ def make_valid_and_keep_geom_type(
824
824
  geoms = GeoSeries(geoms)
825
825
  geoms.index = range(len(geoms))
826
826
  geoms.loc[:] = make_valid(geoms.to_numpy())
827
- geoms = geoms.explode(index_parts=False).pipe(to_single_geom_type, geom_type)
828
- only_one = geoms.groupby(level=0).transform("size") == 1
829
- one_hit = geoms[only_one]
830
- many_hits = geoms[~only_one].groupby(level=0).agg(unary_union)
831
- return pd.concat([one_hit, many_hits]).sort_index()
827
+ geoms_with_correct_type = geoms.explode(index_parts=False).pipe(
828
+ to_single_geom_type, geom_type
829
+ )
830
+ only_one = geoms_with_correct_type.groupby(level=0).transform("size") == 1
831
+ one_hit = geoms_with_correct_type[only_one]
832
+ many_hits = geoms_with_correct_type[~only_one].groupby(level=0).agg(unary_union)
833
+ geoms_with_wrong_type = geoms.loc[~geoms.index.isin(geoms_with_correct_type.index)]
834
+ return pd.concat([one_hit, many_hits, geoms_with_wrong_type]).sort_index()
832
835
 
833
836
 
834
837
  def _agg_geoms(g: np.ndarray, grid_size: int | float | None = None) -> Geometry:
@@ -128,7 +128,7 @@ def read_geopandas(
128
128
  return gpd.GeoDataFrame(
129
129
  _read_partitioned_parquet(
130
130
  gcs_path,
131
- read_func=_read_geopandas,
131
+ read_func=pq.read_table,
132
132
  file_system=file_system,
133
133
  mask=mask,
134
134
  filters=filters,
@@ -145,7 +145,7 @@ def read_geopandas(
145
145
  read_func = gpd.read_file
146
146
 
147
147
  with file_system.open(gcs_path, mode="rb") as file:
148
- df = _read_geopandas(
148
+ return _read_geopandas(
149
149
  file,
150
150
  read_func=read_func,
151
151
  file_format=file_format,
@@ -153,8 +153,6 @@ def read_geopandas(
153
153
  **kwargs,
154
154
  )
155
155
 
156
- return df
157
-
158
156
 
159
157
  def _read_geopandas_from_iterable(
160
158
  paths, mask, file_system, use_threads, pandas_fallback, **kwargs
@@ -242,8 +240,13 @@ def _get_geo_metadata(file, file_system) -> dict:
242
240
  try:
243
241
  meta = pq.read_schema(file).metadata
244
242
  except FileNotFoundError:
245
- with file_system.open(file, "rb") as f:
246
- meta = pq.read_schema(f).metadata
243
+ try:
244
+ with file_system.open(file, "rb") as f:
245
+ meta = pq.read_schema(f).metadata
246
+ except Exception as e:
247
+ raise e.__class__(f"{file}: {e}") from e
248
+ except Exception as e:
249
+ raise e.__class__(f"{file}: {e}") from e
247
250
 
248
251
  return json.loads(meta[b"geo"])
249
252
 
@@ -763,21 +766,23 @@ def _read_partitioned_parquet(
763
766
 
764
767
  if results:
765
768
  if all(isinstance(x, DataFrame) for x in results):
766
- results = pd.concat(results)
769
+ return pd.concat(results)
767
770
  else:
768
771
  geo_metadata = _get_geo_metadata(next(iter(child_paths)), file_system)
769
- results = _arrow_to_geopandas(
772
+ return _arrow_to_geopandas(
770
773
  pyarrow.concat_tables(
771
774
  results,
772
775
  promote_options="permissive",
773
776
  ),
774
777
  geo_metadata,
775
778
  )
776
- return results
777
779
 
778
780
  # add columns to empty DataFrame
779
781
  first_path = next(iter(child_paths + [path]))
780
- return pd.DataFrame(columns=_get_columns(first_path, file_system))
782
+ df = pd.DataFrame(columns=_get_columns(first_path, file_system))
783
+ if "columns" in kwargs:
784
+ return df[list(kwargs["columns"])]
785
+ return df
781
786
 
782
787
 
783
788
  def paths_are_equal(path1: Path | str, path2: Path | str) -> bool:
sgis/maps/explore.py CHANGED
@@ -646,6 +646,10 @@ class Explore(Map):
646
646
  else:
647
647
  self._create_continous_map()
648
648
 
649
+ if not self.map:
650
+ print("No data, no map")
651
+ return
652
+
649
653
  if self.out_path:
650
654
  with self.file_system.open(self.out_path, "w") as f:
651
655
  f.write(self.map._repr_html_())
sgis/maps/map.py CHANGED
@@ -263,10 +263,6 @@ class Map:
263
263
  self._gdfs[i][self.column] = to_string_via_int(gdf[self.column])
264
264
  self._gdf[self.column] = to_string_via_int(self._gdf[self.column])
265
265
 
266
- # def __getattr__(self, attr: str) -> Any:
267
- # """Search for attribute in kwargs."""
268
- # return self.kwargs.get(attr, super().__getattribute__(attr))
269
-
270
266
  def __bool__(self) -> bool:
271
267
  """True of any gdfs with more than 0 rows."""
272
268
  return bool(len(self._gdfs) + len(self._gdf))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ssb-sgis
3
- Version: 1.1.7
3
+ Version: 1.1.9
4
4
  Summary: GIS functions used at Statistics Norway.
5
5
  Home-page: https://github.com/statisticsnorway/ssb-sgis
6
6
  License: MIT
@@ -13,7 +13,7 @@ sgis/geopandas_tools/general.py,sha256=UPtmgEMhTZw-qMiCCjeTtyBlJWoVE96SSanufPK8M
13
13
  sgis/geopandas_tools/geocoding.py,sha256=n47aFQMm4yX1MsPnTM4dFjwegCA1ZmGUDj1uyu7OJV4,691
14
14
  sgis/geopandas_tools/geometry_types.py,sha256=ijQDbQaZPqPGjBl707H4yooNXpk21RXyatI7itnvqLk,7603
15
15
  sgis/geopandas_tools/neighbors.py,sha256=vduQlHeoZjHyD5pxDbjfonQ3-LAHGfPETxV7-L6Sg4M,16634
16
- sgis/geopandas_tools/overlay.py,sha256=pfRSvHmX7GXkJDkpMQvNgS6LTF6DirzrEZCVPSHDUBs,25582
16
+ sgis/geopandas_tools/overlay.py,sha256=pMQK86t0ixKErHQsP0HC8RXHUXNxDCNdH6FK1MEJamM,25779
17
17
  sgis/geopandas_tools/point_operations.py,sha256=JM4hvfIVxZaZdGNlGzcCurrKzkgC_b9hzbFYN42f9WY,6972
18
18
  sgis/geopandas_tools/polygon_operations.py,sha256=FJ-dXCxLHRsmp0oXsmBOFRprFFwmhrxqOPZkW2WWWQM,50088
19
19
  sgis/geopandas_tools/polygons_as_rings.py,sha256=BX_GZS6F9I4NbEpiOlNBd7zywJjdfdJVi_MkeONBuiM,14941
@@ -21,15 +21,15 @@ sgis/geopandas_tools/sfilter.py,sha256=SLcMYprQwnY5DNo0R7TGXk4m6u26H8o4PRn-RPhme
21
21
  sgis/helpers.py,sha256=_h7ke9hJrRNhHW-ZX3gA95fOrX2s1ADKBMxc94p2F4Q,9627
22
22
  sgis/io/__init__.py,sha256=uyBr20YDqB2bQttrd5q1JuGOvX32A-MSvS7Wmw5f5qg,177
23
23
  sgis/io/_is_dapla.py,sha256=wmfkSe98IrLhUg3dtXZusV6OVC8VlY1kbc5EQDf3P-Q,358
24
- sgis/io/dapla_functions.py,sha256=JrMmgdFPgXYUDMCzZcWLv2NyDuzUjwxCkHUC8QiBazQ,30067
24
+ sgis/io/dapla_functions.py,sha256=1jg-OOGRMceJO4b_r9NH9tNRuj3ve352rCec3hRrdAY,30287
25
25
  sgis/io/opener.py,sha256=HWO3G1NB6bpXKM94JadCD513vjat1o1TFjWGWzyVasg,898
26
26
  sgis/io/read_parquet.py,sha256=FvZYv1rLkUlrSaUY6QW6E1yntmntTeQuZ9ZRgCDO4IM,3776
27
27
  sgis/maps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  sgis/maps/examine.py,sha256=Pb0dH8JazU5E2svfQrzHO1Bi-sjy5SeyY6zoeMO34jE,9369
29
- sgis/maps/explore.py,sha256=Vdt1-vFKWkJxL-odh3rn2YlKpWw6Ew0bu8U3KURThNc,47797
29
+ sgis/maps/explore.py,sha256=ReML94ek49vkToXRK9vA_c5Zzg8O7n0GoeqyeuwaBpo,47879
30
30
  sgis/maps/httpserver.py,sha256=eCDoB9x74kSLiGEj2X3O91t3oscY_ia17UNuaaJ6tCc,2472
31
31
  sgis/maps/legend.py,sha256=lVRVCkhPmJRjGK23obFJZAO3qp6du1LYnobkkN7DPkc,26279
32
- sgis/maps/map.py,sha256=bvEQqHgdi8ZGQaKxIy1yIYVOKZ7sPIWo6zoWgo0IpwU,30570
32
+ sgis/maps/map.py,sha256=vvdWSYZN9U0pbv6-l6l5xG3HUWj09fE4qloOe9fF8L8,30403
33
33
  sgis/maps/maps.py,sha256=gxu0rgcVygjudRtM1dVRmsUMilMUIg3vG-UgvASM91E,23072
34
34
  sgis/maps/norge_i_bilder.json,sha256=W_mFfte3DxugWbEudZ5fadZ2JeFYb0hyab2Quf4oJME,481311
35
35
  sgis/maps/thematicmap.py,sha256=w6q4_gIr8BubQgsPJkc6WXk-tmplDLGcKyjphhFp7ng,21873
@@ -59,7 +59,7 @@ sgis/raster/indices.py,sha256=-J1HYmnT240iozvgagvyis6K0_GHZHRuUrPOgyoeIrY,223
59
59
  sgis/raster/regex.py,sha256=kYhVpRYzoXutx1dSYmqMoselWXww7MMEsTPmLZwHjbM,3759
60
60
  sgis/raster/sentinel_config.py,sha256=nySDqn2R8M6W8jguoBeSAK_zzbAsqmaI59i32446FwY,1268
61
61
  sgis/raster/zonal.py,sha256=D4Gyptw-yOLTCO41peIuYbY-DANsJCG19xXDlf1QAz4,2299
62
- ssb_sgis-1.1.7.dist-info/LICENSE,sha256=np3IfD5m0ZUofn_kVzDZqliozuiO6wrktw3LRPjyEiI,1073
63
- ssb_sgis-1.1.7.dist-info/METADATA,sha256=c-fXSCy0eK6NKycntm8iC0GpuM_J2xTnXcdTV8tnmzM,11740
64
- ssb_sgis-1.1.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
65
- ssb_sgis-1.1.7.dist-info/RECORD,,
62
+ ssb_sgis-1.1.9.dist-info/LICENSE,sha256=np3IfD5m0ZUofn_kVzDZqliozuiO6wrktw3LRPjyEiI,1073
63
+ ssb_sgis-1.1.9.dist-info/METADATA,sha256=BVkpmYvkcTxMKuyy6ixUsIRrasOpKsgYAMm2Y5qwM9o,11740
64
+ ssb_sgis-1.1.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
65
+ ssb_sgis-1.1.9.dist-info/RECORD,,