adawang1210 opened a new pull request, #806:
URL: https://github.com/apache/burr/pull/806
## Summary
Serializing state that contains a pandas DataFrame without configuring
`pandas_kwargs` failed with an opaque internal error (`TypeError:
serialize_pandas_df() missing 1 required positional argument: 'pandas_kwargs'`,
or `KeyError: 'path'` if `path` was missing). There was also no way to tell
*which* state field failed. Serde failures now raise clear, actionable errors.
Before:
```
TypeError: serialize_pandas_df() missing 1 required positional argument:
'pandas_kwargs'
```
After:
```
ValueError: Failed to serialize state field 'output' (value of type
DataFrame): Serializing a pandas
DataFrame requires a `path` entry in `pandas_kwargs` -- this is the base
path where the dataframe is
saved as a parquet file. Pass it through whatever triggers serialization,
e.g.
`LocalTrackingClient(..., serde_kwargs={"pandas_kwargs": {"path":
"/some/dir"}})` or
`state.serialize(pandas_kwargs={"path": "/some/dir"})`. Got
pandas_kwargs=None.
```
## Related issue
Addresses the "make it clear if we do not have the values we need" and
"type-check the values coming in" parts of #351.
## Changes made
- `burr/integrations/serde/pandas.py`: `pandas_kwargs` is now optional in
the signature; the serializer validates it and raises an informative
`ValueError` when `path` is missing; the deserializer no longer requires
`pandas_kwargs` at all (the parquet path is embedded in the serialized value).
- `burr/core/state.py`: `State.serialize` / `State.deserialize` wrap serde
failures with the offending field name (chained with `from e` so the original
traceback is preserved).
- `burr/core/serde.py`: unknown deserializer keys now report the registered
keys and hint that the registering module may not have been imported.
- `tests/core/test_serde.py`, `tests/integrations/serde/test_pandas.py`:
cover the missing-kwargs, missing-path, unknown-key, and kwargs-free
deserialization cases.
## How to test
```bash
pytest tests/core/test_serde.py tests/integrations/serde/test_pandas.py
```
## Checklist
- [x] Tests added or updated
- [x] All tests pass locally (`pytest tests/
--ignore=tests/integration_tests`: 577 passed, 5 skipped)
- [x] Commits signed off (`git commit -s`)
- [x] Pre-commit hooks pass (black, isort, flake8)
- [x] CONTRIBUTING.md guidelines followed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]