Closed the-matt-morris closed 2 years ago
I can verify this issue with pandera 0.11.0
. Pretty annoying. Besides that: awesome package!
This need to be documented better, but you need to supply the check_name=True
argument to pa.Field
in order to preserve single-index schema metadata when converting to_schema
.
See example here
The API reference has a more complete description: https://pandera.readthedocs.io/en/stable/reference/generated/pandera.model_components.Field.html#pandera.model_components.Field
check_name (Optional[bool]) – Whether to check the name of the column/index during validation. None is the default behavior, which translates to True for columns and multi-index, and to False for a single index.
This is the default behavior because, in many cases, single-index dataframes are often not named, and there's no way to have an un-named index in SchemaModel
s. This caused an issue where validation would fail since the SchemaModel
s with indexes would try to validate some index name (e.g. foo
in the issue description), see #326.
Hence the check_name=None
arg has different behavior depending on single or multi-array indexes.
I can verify this issue with pandera 0.11.0. Pretty annoying.
Any chance you want to channel that energy to a PR with an example in the docs somewhere on this page @hoffch ?? 😀
@cosmicBboy , thank you for the detailed explanation on this. I won't be able to get to it right away, but I can submit a PR with example in the docs.
@cosmicBboy Thanks for the clarification, the rationale is pretty convincing. Unfortunately, I can't contribute a PR in the forseeable future. Double thanks to @the-matt-morris for doing so instead of me!
Love the work this library is enabling!
Describe the bug A clear and concise description of what the bug is.
Code Sample, a copy-pastable example
The names are kept when using a multi-index, but not when a single index is specified, as above.
Expected behavior
The name attribute of the index should be
foo
in the above example.Desktop (please complete the following information):
Workaround
There's gotta be a better way to do this, but here's my hacky way to get this to work for now: