Skip to content

Commit 833341b

Browse files
fix: ensure windows newlines are read correctly (#5)
1 parent 6267551 commit 833341b

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ A library for reading tables from an Access database into Polars dataframes, usi
55

66
A tiny, `subprocess`-based tool for reading a
77
[MS Access](https://products.office.com/en-us/access)
8-
database (`.rdb`) as a [Python Polars Dataframe](https://docs.pola.rs).
8+
database (`.rdb` or `.accdb`) as a [Python Polars Dataframe](https://docs.pola.rs).
99

1010
## Installation
1111

1212
To read the database, this package thinly wraps
1313
[MDBTools](https://github.com/mdbtools/mdbtools).
1414

15-
If you are on `OSX`, install it via [Homebrew](http://brew.sh/):
15+
If you are on `macOS`, install it via [Homebrew](http://brew.sh/):
1616

1717
```sh
1818
$ brew install mdbtools
@@ -24,7 +24,7 @@ $ sudo apt install mdbtools
2424
```
2525

2626
If you are on `Windows`, it's a little tougher. Install `mdbtools` for [Windows](https://github.com/lsgunth/mdbtools-win). Manually add to PATH.
27-
1. Download the mdb-tools files from Windows link above. Visit the Releases section, then downloadi the part that says "Source Code (zip)".
27+
1. Download the mdb-tools files from Windows link above. Visit the Releases section, then download the part that says "Source Code (zip)".
2828
2. Extract that to somewhere like `C:/bin/mdbtools-win/mdbtools-win-1.0.0`.
2929
3. Follow these instructions to [add that folder to your environment path](https://linuxhint.com/add-directory-to-path-environment-variables-windows/) (Method 1, but use the path to the mdbtools executable files).
3030
4. Restart your computer or just close and re-open the program you're running it from. You can test that it works by opening a terminal and running `mdb-tables --help` and see that it doesn't fail.
@@ -40,11 +40,10 @@ $ pip install polars_access_mdbtools
4040
import polars as pl
4141
import polars_access_mdbtools as pl_access
4242

43-
file_path = 'path_to_file.mdb'
44-
pl_access.list_table_names(file_path)
45-
46-
df = pl_access.read_table(file_path, table_name='your_table_name')
43+
file_path = "path_to_file.mdb"
44+
print(pl_access.list_table_names(file_path))
4745

46+
df: pl.DataFrame = pl_access.read_table(file_path, table_name="your_table_name")
4847
```
4948

5049
## Acknowledgements

src/polars_access_mdbtools/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io
44
import locale
5+
import os
56
import re
67
import subprocess
78
import warnings
@@ -248,6 +249,11 @@ def read_table(
248249
incoming_bytes = proc.stdout.read()
249250
incoming_str = incoming_bytes.decode(locale.getpreferredencoding())
250251
csv_re_encoded = incoming_str.encode("utf-8")
252+
253+
# If on Windows, replace CRLF with LF.
254+
if os.name == "nt":
255+
csv_re_encoded = csv_re_encoded.replace(b"\r\n", b"\n")
256+
251257
csv_io = io.BytesIO(csv_re_encoded)
252258

253259
# Silence this warning:

0 commit comments

Comments
 (0)