Skip to content

Commit ca8af93

Browse files
committed
Fix geoparquet issues
1 parent 1c97e8b commit ca8af93

File tree

7 files changed

+28
-23
lines changed

7 files changed

+28
-23
lines changed

vecorel_cli/cli/path_url.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import click
21
import pathlib
32

4-
from ..vecorel.util import is_url, get_fs
3+
import click
54
from yarl import URL
65

7-
IGNORE_FILES = ["collection.json", "catalog.json"] # likely STAC
6+
from ..vecorel.util import get_fs, is_url
7+
8+
IGNORE_FILES = ["collection.json", "catalog.json"] # likely STAC
9+
810

911
class PathOrURL(click.ParamType):
1012
name = "path_or_url"
@@ -39,7 +41,9 @@ def convert(self, value, param, ctx):
3941
if fs.exists(value):
4042
return URL(value)
4143
else:
42-
self.fail(f"URL '{value}' is does not exist or is currently unavailable.", param, ctx)
44+
self.fail(
45+
f"URL '{value}' is does not exist or is currently unavailable.", param, ctx
46+
)
4347

4448
# Otherwise, validate as a local path
4549
filepath = self.path_type.convert(value, param, ctx)
@@ -57,7 +61,7 @@ def convert(self, value, param, ctx):
5761
self.fail(
5862
f"File '{filepath}' must have one of the following extensions: {', '.join(self.extensions)}",
5963
param,
60-
ctx
64+
ctx,
6165
)
6266
return filepath
6367

vecorel_cli/conversion/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def download_files(self, uris, cache_folder=None, **kwargs):
134134
zip_file.extractall(zip_folder)
135135
except NotImplementedError as e:
136136
if str(e) != "That compression method is not supported":
137-
raise
137+
raise e
138138
import zipfile_deflate64
139139

140140
with zipfile_deflate64.ZipFile(cache_file, "r") as zip_file:

vecorel_cli/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, dataset: str):
7575
try:
7676
self.converter = converters.load(self.dataset)
7777
except (ImportError, NameError, OSError, RuntimeError, SyntaxError) as e:
78-
raise Exception(f"Converter for '{self.dataset}' not available or faulty: {e}")
78+
raise Exception(f"Converter for '{self.dataset}' not available or faulty: {e}") from e
7979

8080
@runnable
8181
def convert(

vecorel_cli/converters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def get_class(self, name):
8686
base_class = self.get_base_class()
8787
try:
8888
module = self.get_module(name)
89-
except ModuleNotFoundError:
90-
raise ValueError(f"Converter '{name}' not found")
89+
except ModuleNotFoundError as e:
90+
raise ValueError(f"Converter '{name}' not found") from e
9191

9292
try:
9393
clazz = next(

vecorel_cli/encoding/geoparquet.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import json
22
from pathlib import Path
33
from typing import Optional, Union
4-
from yarl import URL
54

65
import pyarrow as pa
76
import pyarrow.parquet as pq
87
from geopandas import GeoDataFrame
98
from geopandas.io.arrow import _arrow_to_geopandas
109
from pyarrow import NativeFile
1110
from pyarrow.fs import FSSpecHandler, PyFileSystem
11+
from yarl import URL
1212

1313
from ..const import GEOPARQUET_DEFAULT_VERSION, GEOPARQUET_VERSIONS
1414
from ..encoding.geojson import VecorelJSONEncoder
@@ -181,17 +181,18 @@ def write(
181181
dtype = schema.get("type")
182182

183183
# Convert the data types in the GeoDataFrame
184-
gp_type = get_geopandas_dtype(dtype, required, schema)
185-
if gp_type is None:
186-
self.warning(f"{column}: No type conversion available for {dtype}")
187-
else:
188-
try:
189-
if callable(gp_type):
190-
data[column] = gp_type(data[column])
191-
else:
192-
data[column] = data[column].astype(gp_type, copy=False)
193-
except Exception as e:
194-
self.warning(f"{column}: Can't convert to {dtype}: {e}")
184+
if dtype is not None:
185+
gp_type = get_geopandas_dtype(dtype, required, schema)
186+
if gp_type is None:
187+
self.warning(f"{column}: No type conversion available for {dtype}")
188+
else:
189+
try:
190+
if callable(gp_type):
191+
data[column] = gp_type(data[column])
192+
else:
193+
data[column] = data[column].astype(gp_type, copy=False)
194+
except Exception as e:
195+
self.warning(f"{column}: Can't convert to {dtype}: {e}")
195196

196197
# Create the Parquet schema
197198
field = None

vecorel_cli/validation/geoparquet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _validate(self, num: Optional[int] = None, schema_map: SchemaMapping = {}):
1818

1919
# Load data
2020
try:
21-
data = self.encoding.read(num=num, hydrate=True)
21+
data = self.encoding.read(num=num, schema_map=schema_map, hydrate=True)
2222
except Exception as e:
2323
return self.error(e)
2424

vecorel_cli/vecorel/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def resolve_schema_uris(
5151
if validator:
5252
validator.error(message)
5353
else:
54-
raise ValueError(message)
54+
raise ValueError(message) from e
5555

5656
return loaded
5757

0 commit comments

Comments
 (0)