how to define a DataFrameModel that can have arbitrary number of columns but each of them should be float. #1210
-
I have a function that can return arbitrary number of columns with the only constraint that each of them will be float. How can I create a DataFrameModel that enforces this and works nicely with mypy
|
Beta Was this translation helpful? Give feedback.
Answered by
cosmicBboy
Jun 1, 2023
Replies: 1 comment 1 reply
-
Hi @rja172 you can use the class FloatSchema(pa.DataFrameModel):
col: pa.Series[float] = pa.Field(regex=True, alias=".+") Or you can specify the type at the dataframe-level with a Config class class FloatSchema(pa.DataFrameModel):
class Config:
dtype = float |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cosmicBboy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @rja172 you can use the
regex=True
combined withalias=...
argumentsOr you can specify the type at the dataframe-level with a Config class