PERF: Reduce Cyclomatic Complexity in from_records()
Modularized the from_records() function to improve readability and reduce cyclomatic
complexity. Extracted code blocks into helper functions, making the code more
understandable and maintaining the original structure.

pre-commit.ci autofix Thanks for the PR, but it's not clear to me that these changes are more beneficial and additionally tests are failing. Going to close, but it's advisable to first open an issue to describe the issue you are trying to solve here and get buy-in from a core dev before proceeding.