22
33import glob
44import json
5- from abc import ABC , abstractmethod
65from typing import Any , Container , Dict , Iterator , List , Optional , Sequence , Union , cast
76
87import numpy as np
@@ -89,31 +88,31 @@ def options(self) -> Dict[str, Any]:
8988 return dict (self ._options )
9089
9190 def pipeline (self , * arrays : np .ndarray ) -> Pipeline :
92- return Pipeline ((self ,), arrays = arrays )
91+ return Pipeline ((self ,), arrays )
9392
9493 def __or__ (self , other : Union [Stage , Pipeline ]) -> Pipeline :
9594 return Pipeline ((self , other ))
9695
9796
98- class InferableTypeStage (ABC , Stage ):
99- @ staticmethod
100- @ abstractmethod
101- def infer_type ( filename : str ) -> str :
102- """Infer the driver type from the filename"""
97+ class InferableTypeStage (Stage ):
98+ def __init__ ( self , filename : Optional [ str ] = None , ** options : Any ):
99+ if filename :
100+ options [ "filename" ] = filename
101+ super (). __init__ ( ** options )
103102
104103 @property
105104 def type (self ) -> str :
106105 try :
107106 return super ().type
108107 except KeyError :
109- return self .infer_type (self ._options ["filename" ])
108+ filename = self ._options .get ("filename" )
109+ return str (self ._infer_type (filename ) if filename else "" )
110110
111+ _infer_type = staticmethod (lambda filename : "" )
111112
112- class Reader (InferableTypeStage ):
113- infer_type = staticmethod (libpdalpython .infer_reader_driver )
114113
115- def __init__ ( self , filename : str , ** options : Any ):
116- super (). __init__ ( filename = filename , ** options )
114+ class Reader ( InferableTypeStage ):
115+ _infer_type = staticmethod ( libpdalpython . infer_reader_driver )
117116
118117
119118class Filter (Stage ):
@@ -122,10 +121,7 @@ def __init__(self, type: str, **options: Any):
122121
123122
124123class Writer (InferableTypeStage ):
125- infer_type = staticmethod (libpdalpython .infer_writer_driver )
126-
127- def __init__ (self , filename : Optional [str ] = None , ** options : Any ):
128- super ().__init__ (filename = filename , ** options )
124+ _infer_type = staticmethod (libpdalpython .infer_writer_driver )
129125
130126
131127def _parse_stages (text : str ) -> Iterator [Stage ]:
0 commit comments