Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit cde75c8

Browse files
committed
Further optimise get_matching_variables
1 parent 37b54a8 commit cde75c8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

root_pandas/readwrite.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ def get_nonscalar_columns(array):
6161
def get_matching_variables(branches, patterns, fail=True):
6262
# Convert branches to a set to make x "in branches" O(1) on average
6363
branches = set(branches)
64-
selected = []
65-
for pattern in patterns:
64+
patterns = set(patterns)
65+
# Find any trivial matches
66+
selected = list(branches.intersection(patterns))
67+
# Any matches that weren't trivial need to be looped over...
68+
for pattern in patterns.difference(selected):
6669
found = False
67-
# Avoid using fnmatch if the pattern can only match literally
70+
# Avoid using fnmatch if the pattern if possible
6871
if re.findall(r'(\*)|(\?)|(\[.*\])|(\[\!.*\])', pattern):
6972
for match in fnmatch.filter(branches, pattern):
7073
found = True

0 commit comments

Comments
 (0)