python-osw-validation 0.4.0__py3-none-any.whl → 0.4.2__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.
@@ -2,6 +2,7 @@ import os
2
2
  import gc
3
3
  import json
4
4
  import math
5
+ import numbers
5
6
  from typing import Dict, Any, Optional, List, Tuple
6
7
  import geopandas as gpd
7
8
  import jsonschema_rs
@@ -14,6 +15,7 @@ from .helpers import (
14
15
  _err_kind,
15
16
  _feature_index_from_error,
16
17
  _pretty_message,
18
+ _read_geojson_without_ext,
17
19
  )
18
20
 
19
21
  SCHEMA_PATH = os.path.join(os.path.dirname(__file__), 'schema')
@@ -282,9 +284,7 @@ class OSWValidation:
282
284
  def _is_nullish_value(self, value: Any) -> bool:
283
285
  if value is None:
284
286
  return True
285
- if isinstance(value, str) and value.strip().lower() in {"null", "nan"}:
286
- return True
287
- return isinstance(value, float) and math.isnan(value)
287
+ return isinstance(value, numbers.Real) and math.isnan(value)
288
288
 
289
289
  def _collect_nullish_property_paths(self, obj: Any, prefix: str = "") -> List[Tuple[str, Any]]:
290
290
  paths: List[Tuple[str, Any]] = []
@@ -302,6 +302,13 @@ class OSWValidation:
302
302
  paths.append((prefix or "value", obj))
303
303
  return paths
304
304
 
305
+ def _collect_nullish_extension_property_paths(self, props: Dict[str, Any]) -> List[Tuple[str, Any]]:
306
+ paths: List[Tuple[str, Any]] = []
307
+ for key, value in props.items():
308
+ if isinstance(key, str) and key.startswith("ext:"):
309
+ paths.extend(self._collect_nullish_property_paths(value, key))
310
+ return paths
311
+
305
312
  def _contains_disallowed_features_for_02(self, geojson_data: Dict[str, Any]) -> set:
306
313
  """Detect Tree coverage or Custom content in legacy 0.2 datasets.
307
314
 
@@ -419,7 +426,7 @@ class OSWValidation:
419
426
  osw_file = next((osw_key for osw_key in OSW_DATASET_FILES.keys()
420
427
  if osw_key in os.path.basename(file_path)), '')
421
428
  try:
422
- gdf = gpd.read_file(file_path)
429
+ gdf = _read_geojson_without_ext(file_path)
423
430
  except Exception as e:
424
431
  self.log_errors(
425
432
  message=f"Failed to read '{os.path.basename(file_path)}' as GeoJSON: {e}",
@@ -557,7 +564,7 @@ class OSWValidation:
557
564
  file_path = os.path.join(file)
558
565
  file_name = os.path.basename(file)
559
566
  try:
560
- extensionFile = gpd.read_file(file_path)
567
+ extensionFile = _read_geojson_without_ext(file_path)
561
568
  except Exception as e:
562
569
  self.log_errors(
563
570
  message=f"Failed to read extension '{file_name}' as GeoJSON: {e}",
@@ -675,8 +682,8 @@ class OSWValidation:
675
682
 
676
683
  filename = os.path.basename(file_path)
677
684
 
678
- # Upfront guard: reject null/NaN values in feature properties.
679
- # This runs before schema validation to surface data quality issues first.
685
+ # Upfront guard: reject null/NaN values in free-form extension properties.
686
+ # Schema-owned properties are left to schema validation.
680
687
  features = geojson_data.get("features", []) if isinstance(geojson_data, dict) else []
681
688
  found_nullish = False
682
689
  for idx, feature in enumerate(features):
@@ -685,7 +692,7 @@ class OSWValidation:
685
692
  props = feature.get("properties")
686
693
  if not isinstance(props, dict):
687
694
  continue
688
- bad_paths = self._collect_nullish_property_paths(props)
695
+ bad_paths = self._collect_nullish_extension_property_paths(props)
689
696
  for path, bad_value in bad_paths:
690
697
  if len(self.errors) >= max_errors:
691
698
  return False
@@ -1,6 +1,30 @@
1
1
  from typing import Optional
2
+ import json
2
3
  import re
3
4
 
5
+ import geopandas as gpd
6
+
7
+
8
+ def _read_geojson_without_ext(file_path: str) -> gpd.GeoDataFrame:
9
+ """Load a GeoJSON file into a GeoDataFrame with ext:* properties removed.
10
+
11
+ Why: pyogrio/GDAL infers a single dtype per property column when reading
12
+ GeoJSON. Extension tags (ext:*) are free-form by spec and may legitimately
13
+ mix numbers and strings across features, which breaks that inference and
14
+ surfaces as a confusing JSON parse error. Schema validation has already
15
+ accepted these properties; the GeoDataFrame is only used for geometry and
16
+ _id-based integrity checks, so dropping ext:* here is safe.
17
+ """
18
+ with open(file_path, 'r') as f:
19
+ data = json.load(f)
20
+ for feature in data.get('features', []):
21
+ props = feature.get('properties')
22
+ if isinstance(props, dict):
23
+ for key in [k for k in props if isinstance(k, str) and k.startswith('ext:')]:
24
+ del props[key]
25
+ crs = (data.get('crs') or {}).get('properties', {}).get('name')
26
+ return gpd.GeoDataFrame.from_features(data.get('features', []), crs=crs)
27
+
4
28
  _ADDITIONAL_PROPERTIES_RE = re.compile(
5
29
  r"Additional properties are not allowed \('(?P<tag>[^']+)' was unexpected\)"
6
30
  )
@@ -1 +1 @@
1
- __version__ = '0.4.0'
1
+ __version__ = '0.4.2'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_osw_validation
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Python library for OSW validation
5
5
  Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
6
6
  Author: Sujata Misra
@@ -31,6 +31,10 @@ Dynamic: summary
31
31
 
32
32
  # TDEI python lib OSW validation package
33
33
 
34
+ [![python-osw-validation](https://img.shields.io/pypi/v/python-osw-validation?label=python-osw-validation&cacheSeconds=60&t=1)](https://pypi.org/project/python-osw-validation/)
35
+ [![Unit Tests](https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/actions/workflows/unit_tests.yml)
36
+ ![Coverage](https://raw.githubusercontent.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/actions/badges/coverage.svg)
37
+
34
38
  This package validates OSW GeoJSON datasets packaged as a ZIP file.
35
39
 
36
40
  ## System requirements
@@ -44,7 +48,7 @@ This package validates OSW GeoJSON datasets packaged as a ZIP file.
44
48
  - Extracts the provided ZIP file
45
49
  - Finds supported OSW dataset files inside the extracted directory
46
50
  - Validates each file (`edges`, `lines`, `nodes`, `points`, `polygons`, and `zones`) against the matching schema
47
- - Performs an upfront data-quality check for null-like placeholders in feature properties (for example `null`, `NaN`, `"null"`, `"nan"`)
51
+ - Performs an upfront data-quality check for actual null and numeric NaN values in `ext:*` extension properties (for example JSON `null` or numeric `NaN`; string values like `"null"` and `"nan"` are not rejected by this precheck)
48
52
  - Runs cross-file integrity checks such as duplicate `_id` detection and edge or zone references back to nodes
49
53
  - Returns a `ValidationResult` object with `is_valid`, `errors`, and `issues`
50
54
 
@@ -77,8 +81,8 @@ print(result.issues) # capped by the same max_errors limit
77
81
 
78
82
  - `errors`: high-level validation messages, capped by `max_errors` (default `20`).
79
83
  - `issues`: detailed per-feature validation issues, also capped by `max_errors`.
80
- - If null-like placeholders are found in feature `properties`, validation fails early before schema checks with actionable messages such as:
81
- - `Invalid value at 'climb': 'null'. Null/NaN placeholders are not allowed; provide a valid value or remove this property.`
84
+ - If actual null or numeric NaN values are found in `ext:*` extension properties, validation fails early before schema checks with actionable messages such as:
85
+ - `Invalid value at 'ext:metadata.score': nan. Null/NaN placeholders are not allowed; provide a valid value or remove this property.`
82
86
  - For enum validation, long allowed-value lists are summarized as:
83
87
  - first 5 values joined by `|`
84
88
  - followed by `| and N more` when applicable.
@@ -1,8 +1,8 @@
1
- python_osw_validation/__init__.py,sha256=GQX6EdJxaYkMVZv0dGjhT1rJgX7FYyR6ksAi-UYayEs,33246
1
+ python_osw_validation/__init__.py,sha256=cK7jzSRUpYZ-QvWUVC3C3dCu7ce-HtKNSTzA1IArpzg,33576
2
2
  python_osw_validation/extracted_data_validator.py,sha256=gEGYLaM_QkK6NrrhVYmNx-jMaNHXC4PbDGf1zKwJre4,6605
3
3
  python_osw_validation/geometry_mapping_validator.py,sha256=KscmfgSwTiXbf8IPx-RXuTIXPYY4PHDwvBeb2WmhpVA,14137
4
- python_osw_validation/helpers.py,sha256=_LgtNoFTjJLqg64zxJLO1Q4dPpui_lWNPNDMnqN8Qck,8106
5
- python_osw_validation/version.py,sha256=2eiWQI55fd-roDdkt4Hvl9WzrTJ4xQo33VzFud6D03U,22
4
+ python_osw_validation/helpers.py,sha256=iLVJZS1-AaLsbP0ngHZLW208dKSnM2k52JFal4Nuxcg,9203
5
+ python_osw_validation/version.py,sha256=zrcTwxP3SA3F1Js78afrfeaZeJr8w2hLtFtEZoUqUmg,22
6
6
  python_osw_validation/zipfile_handler.py,sha256=jXnP-8O5AAOBapuNF3-XdFVM1MHiPaWpl_wlbX-aqhY,2631
7
7
  python_osw_validation/schema/opensidewalks.edges.schema-0.3.json,sha256=Egp--i6ahiUDKY55g_fuv71HkVPtnQN5OW8L_okRa8o,79638
8
8
  python_osw_validation/schema/opensidewalks.lines.schema-0.3.json,sha256=3s-VXiMPv0_wv3yU2iGw8iKjE3Ec1w6QKkUsQURp2II,9470
@@ -11,8 +11,8 @@ python_osw_validation/schema/opensidewalks.points.schema-0.3.json,sha256=WYmlC4Q
11
11
  python_osw_validation/schema/opensidewalks.polygons.schema-0.3.json,sha256=VzDpHv1ZVT42cAk9n3gsFZjS7WcflQzSbjN-aNIVTYM,16286
12
12
  python_osw_validation/schema/opensidewalks.schema-0.3.json,sha256=vyyGzPpqLxr1e5wFfNKzlA1sr6tmhHKM7ntaTk8z5k8,278489
13
13
  python_osw_validation/schema/opensidewalks.zones.schema-0.3.json,sha256=JCqoCJj-dCuPVPHWSUQhRJMebaJ9IrzHWwTVAC6j7dY,11281
14
- python_osw_validation-0.4.0.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
15
- python_osw_validation-0.4.0.dist-info/METADATA,sha256=fIdNFivsf7gvoWIVNtL11MtQ0yzoScgYS1XzHeLRp_o,6080
16
- python_osw_validation-0.4.0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
17
- python_osw_validation-0.4.0.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
18
- python_osw_validation-0.4.0.dist-info/RECORD,,
14
+ python_osw_validation-0.4.2.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
15
+ python_osw_validation-0.4.2.dist-info/METADATA,sha256=fb8PvRfotgMot9cZ1jJ2RfEBX5hpLBrLDHDUjhYfnsE,6731
16
+ python_osw_validation-0.4.2.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
17
+ python_osw_validation-0.4.2.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
18
+ python_osw_validation-0.4.2.dist-info/RECORD,,