Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all use of parquet's validate_schema #110

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions spatialpandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,21 @@ def read_parquet(
engine_kwargs = engine_kwargs or {}
filesystem = validate_coerce_filesystem(path, filesystem, storage_options)

# Load pandas parquet metadata
metadata = _load_parquet_pandas_metadata(
# Load using pyarrow to handle parquet files and directories across filesystems
dataset = pq.ParquetDataset(
path,
filesystem=filesystem,
storage_options=storage_options,
engine_kwargs=engine_kwargs,
#validate_schema=False,
use_legacy_dataset=False,
**engine_kwargs,
**kwargs,
)

metadata = dataset.schema.pandas_metadata

# If columns specified, prepend index columns to it
if columns is not None:
all_columns = set(column['name'] for column in metadata.get('columns', []))
index_col_metadata = metadata.get('index_columns', [])
extra_index_columns = []
for idx_metadata in index_col_metadata:
Expand All @@ -165,20 +170,12 @@ def read_parquet(
name = idx_metadata.get('name', None)
else:
name = None

if name is not None and name not in columns:
if name is not None and name not in columns and name in all_columns:
extra_index_columns.append(name)

columns = extra_index_columns + list(columns)

# Load using pyarrow to handle parquet files and directories across filesystems
df = pq.ParquetDataset(
path,
filesystem=filesystem,
validate_schema=False,
**engine_kwargs,
**kwargs,
).read(columns=columns).to_pandas()
df = dataset.read(columns=columns).to_pandas()

# Import geometry columns, not needed for pyarrow >= 0.16
geom_cols = _get_geometry_columns(metadata)
Expand Down