Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor _select_matching_columns to reduce nesting #8

Open
ulfaslakprecis opened this issue Oct 20, 2023 · 0 comments
Open

Refactor _select_matching_columns to reduce nesting #8

ulfaslakprecis opened this issue Oct 20, 2023 · 0 comments

Comments

@ulfaslakprecis
Copy link
Contributor

ok, how about taking the shorter branch first here? I.e. if field.alias is None:

Also, what do you think about defining three small functions adding semantics and hiding the lowest level branching?

Names can be made more descriptive, but with this it would read something like:

    if field.alias is None:
      # return [column] if no error
      matched = _check_non_alias(df, column, matching_columns_in_df, optional)
      continue

    if field.regex:
        matched = cls._check_alias_regex(df, column, matching_columns_in_df, optional)
    else:
        # returns [field.alias] if no error
        matched = cls._check_alias(df, column, matching_columns_in_df, optional)

    matching_columns_in_df.extend(matched)

(Here these are class methods since cls is used in the message.)

It might also help testing to be more unit-y, i.e, testing each individual _check function.

Originally posted by @pierreprecis in #5 (comment)

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

No branches or pull requests

1 participant