Skip to content

Refactor _select_matching_columns to reduce nesting #8

Description

@ulfaslakprecis

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions