Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 17 additions & 2 deletions src/pdal/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ def __or__(self, other: Union[Stage, Pipeline]) -> Pipeline:
class InferableTypeStage(Stage):
def __init__(self, filename: Optional[str] = None, **options: Any):
if filename:
options["filename"] = filename
if isinstance(filename, dict):
if "path" not in filename:
raise ValueError(f"'path' is missing in the provided filespec: {filename}")
options["filename"] = filename

else:
filespec = {'path':str(filename)}
options["filename"] = filespec
super().__init__(**options)

@property
Expand All @@ -226,7 +233,15 @@ def type(self) -> str:
return super().type
except KeyError:
filename = self._options.get("filename")
return str(self._infer_type(filename) if filename else "")
if isinstance(filename, dict):
if "path" not in filename:
raise ValueError(f"'path' is missing in the provided filespec: {filename}")
path = filename.get('path')
else:
path = str(filename)


return str(self._infer_type(path) if filename else "")

_infer_type = staticmethod(lambda filename: "")

Expand Down
14 changes: 13 additions & 1 deletion test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import sys

from typing import List
from itertools import product
import numpy as np
import pytest
Expand Down Expand Up @@ -284,6 +283,19 @@ def test_infer_stage_type(self):
assert pdal.Writer("foo.xxx").type == ""
assert pdal.Reader().type == ""
assert pdal.Writer().type == ""
assert pdal.Reader({"path": "foo.las"}).type == "readers.las"
assert pdal.Writer({"path": "foo.las"}).type == "writers.las"
assert pdal.Reader({"path": "foo.xxx"}).type == ""
assert pdal.Writer({"path": "foo.xxx"}).type == ""
assert pdal.Reader({}).type == ""
assert pdal.Writer({}).type == ""

def test_filespec(self):
"""Can transit filespecs"""
spec = {'path':'junk.las', 'headers':{'header1':'header_1', 'header2':'header_2'}, 'query':{'query1':'query_1', 'query2':'query_2'}}
assert pdal.Reader(spec).type == "readers.las"
assert pdal.Reader(spec).options['filename']['path'] == "junk.las"
assert pdal.Writer("foo.las").type == "writers.las"

def test_streamable(self):
"""Can we distinguish streamable from non-streamable stages and pipeline"""
Expand Down