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

fix: Expand brackets in async glob expansion #17630

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions crates/polars-io/src/cloud/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ fn extract_prefix_expansion(url: &str) -> PolarsResult<(String, Option<String>)>
let mut expansion = String::new();
let mut last_split_was_wildcard = false;
for split in splits {
let has_star = split.contains('*');
if expansion.is_empty() && !has_star {
if expansion.is_empty() && memchr::memchr2(b'*', b'[', split.as_bytes()).is_none() {
// We are still gathering splits in the prefix.
if !prefix.is_empty() {
prefix.push(DELIMITER);
Expand All @@ -44,7 +43,7 @@ fn extract_prefix_expansion(url: &str) -> PolarsResult<(String, Option<String>)>
expansion.push(DELIMITER);
}
// Handle '.' inside a split.
if split.contains('.') || split.contains('*') {
if memchr::memchr2(b'.', b'*', split.as_bytes()).is_some() {
let processed = split.replace('.', "\\.");
expansion.push_str(&processed.replace('*', "([^/]*)"));
continue;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-io/src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub fn expand_paths_hive(
if path.extension() != ext {
polars_bail!(
InvalidOperation: r#"directory contained paths with different file extensions: \
first path: {}, second path: {}. Please use a glob pattern to explicitly specify
first path: {}, second path: {}. Please use a glob pattern to explicitly specify \
which files to read (e.g. "dir/**/*", "dir/**/*.parquet")"#,
out_paths[i - 1].to_str().unwrap(), path.to_str().unwrap()
);
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/io/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,13 @@ def test_scan_include_file_name(

# Test codepaths that materialize empty DataFrames
assert_frame_equal(lf.head(0).collect(streaming=streaming), df.head(0))


@pytest.mark.write_disk()
def test_async_path_expansion_bracket_17629(tmp_path: Path) -> None:
path = tmp_path / "data.parquet"

df = pl.DataFrame({"x": 1})
df.write_parquet(path)

assert_frame_equal(pl.scan_parquet(tmp_path / "[d]ata.parquet").collect(), df)