Replace assert statements with exceptions (#13871) (#13901)
* Replace assert statements with exceptions (#13871)
* Change f-strings when not needed (flake8)
* Replace assert statements with exceptions (#13871)
* Change f-strings when not needed (flake8)
* Improve error message as suggested by reviewer
* Fix identation bug
* Fix style errors