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

Long non-existing paths are reversed in python pl.read_csv() #7657

Closed
2 tasks done
didriksg opened this issue Mar 20, 2023 · 0 comments · Fixed by #7673
Closed
2 tasks done

Long non-existing paths are reversed in python pl.read_csv() #7657

didriksg opened this issue Mar 20, 2023 · 0 comments · Fixed by #7673
Labels
bug Something isn't working python Related to Python Polars

Comments

@didriksg
Copy link
Contributor

didriksg commented Mar 20, 2023

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

PR #6917 fixed #6853 by limiting the number of characters to 88 in the exception message. However, it also reverses the actual string itself.

It seems like the function:

fn no_such_file_err(file_path: &str) -> PyResult<()> {
let msg = if file_path.len() > 88 {
let file_path: String = file_path.chars().rev().take(88).collect();
format!("No such file or directory: ...{file_path}",)
} else {
format!("No such file or directory: {file_path}",)
};
Err(PyErr::new::<PyFileNotFoundError, _>(msg))
}

and specifically the line
let file_path: String = file_path.chars().rev().take(88).collect();

is responsible for the reversal.

The intended functionality is to use the 88 last characters directly.

Reproducible example

import polars as pl

pl.read_csv('TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTJJnon-existing-long-path')

>> FileNotFoundError: No such file or directory: ...htap-gnol-gnitsixe-nonJJTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Expected behavior

import polars as pl

pl.read_csv('TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTJJnon-existing-long-path')

>> FileNotFoundError: No such file or directory: ...TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTJJnon-existing-long-path

Installed versions

---Version info---
Polars: 0.16.14
Index type: UInt32
Platform: Linux-6.2.6-arch1-1-x86_64-with-glibc2.37
Python: 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201]
---Optional dependencies---
numpy: 1.24.2
pandas: 1.5.3
pyarrow: <not installed>
connectorx: <not installed>
deltalake: <not installed>
fsspec: <not installed>
matplotlib: <not installed>
xlsx2csv: <not installed>
xlsxwriter: <not installed>
@didriksg didriksg added bug Something isn't working python Related to Python Polars labels Mar 20, 2023
@didriksg didriksg changed the title Long non-existing paths are reversed Long non-existing paths are reversed in python pl.read_csv() Mar 20, 2023
didriksg added a commit to didriksg/polars that referenced this issue Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant