exceptions.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. """
  2. Custom exceptions for the seaborn.objects interface.
  3. This is very lightweight, but it's a separate module to avoid circular imports.
  4. """
  5. from __future__ import annotations
  6. class PlotSpecError(RuntimeError):
  7. """
  8. Error class raised from seaborn.objects.Plot for compile-time failures.
  9. In the declarative Plot interface, exceptions may not be triggered immediately
  10. by bad user input (and validation at input time may not be possible). This class
  11. is used to signal that indirect dependency. It should be raised in an exception
  12. chain when compile-time operations fail with an error message providing useful
  13. context (e.g., scaling errors could specify the variable that failed.)
  14. """
  15. @classmethod
  16. def _during(cls, step: str, var: str = "") -> PlotSpecError:
  17. """
  18. Initialize the class to report the failure of a specific operation.
  19. """
  20. message = []
  21. if var:
  22. message.append(f"{step} failed for the `{var}` variable.")
  23. else:
  24. message.append(f"{step} failed.")
  25. message.append("See the traceback above for more information.")
  26. return cls(" ".join(message))