Comments (3)
Looks like a bug in pandera.typing.Series
... I think you can try just the bare type and it should work:
class Schema(pa.DataFrameModel):
city: str
price: LiteralFloat = pa.Field(coerce=True)
The correct implementation of the custom dtype is also:
from pandera.api.polars.types import PolarsData
@polars_engine.Engine.register_dtype
@dtypes.immutable
class LiteralFloat(polars_engine.Float64): # 👈 inherit from polars_engine.Float64, not the polars dtype
def coerce(self, polars_data: PolarsData) -> pl.LazyFrame: # 👈 note the input and output signature
"""If comes across a string, remove commas and coerce it to a float. If it fails, return NaN."""
return polars_data.lazyframe.with_columns( # 👈 must return a lazyframe
pl.col(polars_data.key)
.str.replace(",", "")
.cast(pl.Float64, strict=False)
)
See the polars engine DataType implementation for details on the signatures of these methods:
https://github.com/unionai-oss/pandera/blob/main/pandera/engines/polars_engine.py#L91
I'll look into fixing the SchemaInitError: Invalid annotation 'price: pandera.typing.pandas.Series[__main__.LiteralFloat]'
issue, if you can, would be great if the polars docs can be updated with an example of a custom datatype: https://github.com/unionai-oss/pandera/blob/main/docs/source/polars.md
from pandera.
I'll look into fixing the SchemaInitError: Invalid annotation 'price: pandera.typing.pandas.Series[main.LiteralFloat]' issue
So the whole Series[TYPE]
syntax is only supported in the pandas DataFrameModel and will be deprecated in that API eventually... looking forward to new backends (in this case polars) the more concise bare type will be supported. I'll add a more informative error message here.
from pandera.
That worked, I'll open a PR shortly!
from pandera.
Related Issues (20)
- Add support for polars.Enum
- Polars Enum does not work for Polars verion >=1.0.0 HOT 1
- [Bug?] Ordered: True results in alphabetically ordering
- How to properly validate a `polars.LazyFrame`? HOT 2
- Installation issues when using polars-lts-cpu HOT 6
- Dagster polars dataframe_check HOT 2
- Failed Index Uniqueness Validation for Dask Series HOT 1
- pandera.errors.SchemaErrors.failure_cases returns incorrect columns when used with regex column names HOT 1
- Polars DataFrameModel `to_json_schema()` fails on pl.Datetime column
- TypeError when calling _type_check on parameterized GenericModel in pydantic v1
- Time series integrity
- Improve `pd.Series` error message to include index / row number
- reset_index() not functioning properly with more than two indexes
- Parameterized field names
- `check_types` decorator does not validate dataframe(s) in returned sequence HOT 2
- typing module removed from root __init__ HOT 5
- Error when no column adheres to reg_ex with Pyspark SQL DataFrameModel: 'list' object has no attribute 'tolist'
- Optional doesn't flag column as nullable, when other constraints are added to Field HOT 2
- Union of schemas not working with pandera.pyspark
- Upgrade multimethod to 1.12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandera.