Skip to content

Commit

Permalink
Add --encoding to csv2numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
masaccio committed Oct 12, 2024
1 parent b4dad88 commit 15f479e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "numbers-parser"
packages = [{include = "numbers_parser", from = "src"}]
readme = "README.md"
repository = "https://github.com/masaccio/numbers-parser"
version = "4.13.2"
version = "4.13.3"

[tool.poetry.scripts]
cat-numbers = "numbers_parser._cat_numbers:main"
Expand Down
10 changes: 9 additions & 1 deletion src/numbers_parser/_csv2numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Converter:
no_header: bool = False
reverse: bool = False
whitespace: bool = None
encoding: str = "utf-8"

def __post_init__(self: Converter) -> None:
"""Parse CSV file with Pandas and return a dataframe."""
Expand All @@ -45,7 +46,7 @@ def _read_csv(self) -> None:
dialect = csv.excel
dialect.strict = True
lineno = 1
with open(self.input_filename) as csvfile:
with open(self.input_filename, encoding=self.encoding) as csvfile:
csvreader = csv.reader(csvfile, dialect=dialect)
if self.no_header:
self.header = None
Expand Down Expand Up @@ -333,6 +334,12 @@ def command_line_parser() -> argparse.ArgumentParser:
action="store_true",
help="dates are represented day first in the CSV file (default: false)",
)
parser.add_argument(
"--encoding",
required=False,
default="utf-8",
help="python-style text encoding of the CSV file (default: utf-8)",
)
parser.add_argument(
"--date",
metavar="COLUMNS",
Expand Down Expand Up @@ -400,6 +407,7 @@ def main() -> None:
date_columns=args.date,
input_filename=input_filename,
output_filename=output_filename,
encoding=args.encoding,
)

converter.transform_columns(args.transform)
Expand Down

0 comments on commit 15f479e

Please sign in to comment.