Open edavisau opened 3 months ago
This basically already works: because current normalize_filepath implementation already works with os.PathLike (just needs updated type hints).
normalize_filepath
os.PathLike
The only place where change is needed is here
if isinstance(source, (str, Path)): # -> (str, os.PathLike) instead source = normalize_filepath(source, check_not_directory=False) else: source = [ normalize_filepath(source, check_not_directory=False) for source in source ]
The rest of the change would be type hints
import tempfile import polars as pl tmp_file = tempfile.NamedTemporaryFile() pl.DataFrame(dict(a=[1,2,3])).write_parquet(tmp_file.name) class Foo: def __fspath__(self): return tmp_file.name isinstance(Foo(), os.PathLike) # True pl.read_parquet(Foo()) # TypeError: 'Foo' object is not iterable pl.read_parquet([Foo()]) # shape: (3, 1) # ┌─────┐ # │ a │ # │ --- │ # │ i64 │ # ╞═════╡ # │ 1 │ # │ 2 │ # │ 3 │ # └─────┘
We should be able to support os.PathLike inputs.
A PR is welcome if it includes extensive testing for various pathlike inputs other than pathlib.Path.
pathlib.Path
Description
This basically already works: because current
normalize_filepath
implementation already works withos.PathLike
(just needs updated type hints).The only place where change is needed is here
The rest of the change would be type hints
Example