Skip to content

Commit ca4f993

Browse files
authored
Merge pull request #145 from ocefpaf/guess_encoding
Guess encoding
2 parents f90967b + 5310fb5 commit ca4f993

3 files changed

Lines changed: 5 additions & 10 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ repos:
4040
- id: black
4141
language_version: python3
4242

43-
- repo: https://github.com/pre-commit/mirrors-mypy
44-
rev: v0.950
45-
hooks:
46-
- id: mypy
47-
exclude: docs/source/conf.py
48-
args: [--ignore-missing-imports]
4943

5044
- repo: https://github.com/codespell-project/codespell
5145
rev: v2.1.0

ctd/read.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from io import StringIO
1414
from pathlib import Path
1515

16+
import chardet
1617
import gsw
1718
import numpy as np
1819
import pandas as pd
@@ -50,9 +51,7 @@ def _open_compressed(fname):
5051
cfile = zfile.open(name)
5152
else:
5253
raise ValueError(
53-
"Unrecognized file extension. Expected .gzip, .bz2, or .zip, got {}".format(
54-
extension,
55-
),
54+
f"Unrecognized file extension. Expected .gzip, .bz2, or .zip, got {extension}",
5655
)
5756
contents = cfile.read()
5857
cfile.close()
@@ -74,7 +73,8 @@ def _read_file(fname):
7473
f"Unrecognized file extension. Expected .cnv, .edf, .txt, .ros, or .btl got {extension}",
7574
)
7675
# Read as bytes but we need to return strings for the parsers.
77-
text = contents.decode(encoding="utf-8", errors="replace")
76+
encoding = chardet.detect(contents)["encoding"]
77+
text = contents.decode(encoding=encoding, errors="replace")
7878
return StringIO(text)
7979

8080

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
chardet
12
gsw>=3.3.0
23
matplotlib
34
numpy

0 commit comments

Comments
 (0)