Skip to content

Conversation

aksel2904
Copy link

Overview

This PR refactors the np_can_hold_element function to reduce its cyclomatic complexity and improve maintainability. The function was decomposed into smaller helper functions (_handle_integer_dtype, _handle_float_dtype, etc.), each handling a specific dtype logic. This improves readability and reduces the complexity of the main function.

Changes

  • Refactored np_can_hold_element into smaller helper functions:
    • _handle_integer_dtype
    • _handle_float_dtype
    • _handle_complex_dtype
    • _handle_boolean_dtype
    • _handle_string_dtype
  • Added docstrings to the helper functions for better documentation.
  • Ensured no changes to functionality or behavior during the refactor.
  • Ran flake8 and fixed style issues to comply with the project's code standards.

Testing

  • Verified that all existing tests in the Pandas test suite pass.
  • Confirmed no behavioral changes in np_can_hold_element.

Notes for Reviewers

  • The refactor was aimed at maintainability; the logic remains consistent with the original implementation.
  • Suggestions for additional tests or improvements are welcome.

@aksel2904
Copy link
Author

was in pandas/core/dtypes/cast.py:
image
now in pandas/core/dtypes/cast.py:
image

@mroeschke
Copy link
Member

Thanks for the effort here but the project doesn't enforce any standards with regards to complexity so I don't think this refactor is worthwhile. Going to close but happy to have contributes toward issues labeled good first issue

@mroeschke mroeschke closed this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants