_csv.Error: Could not determine delimiter

89 views
Skip to first unread message

crusty...@gmail.com

unread,
Feb 14, 2019, 10:41:22 PM2/14/19
to Beancount
Hi,

I'm trying to get importing a CSV file to work. bean-identify tells me this:

$ bean-identify personal.import Downloads
**** /home/user/personal/finance/accounting/Downloads/Hudsons.csv
Importer:    importers.hudsons.Importer: "Liabilities:CA:HudsonsBay:Mastercard"
Account:     Liabilities:CA:HudsonsBay:Mastercard

So I know that this part works. However, when I try to do the extract, I get this:

$ bean-extract personal.import Downloads
ERROR:root:Importer importers.hudsons.Importer: "Liabilities:CA:HudsonsBay:Mastercard".extract() raised an unexpected error: Could not determine delimiter
ERROR:root:Traceback: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/beancount/ingest/extract.py", line 191, in extract
    allow_none_for_tags_and_links=allow_none_for_tags_and_links)
  File "/usr/lib/python3/dist-packages/beancount/ingest/extract.py", line 69, in extract_from_file
    new_entries = importer.extract(file, **kwargs)
  File "/usr/lib/python3/dist-packages/beancount/ingest/importers/csv.py", line 186, in extract
    iconfig, has_header = normalize_config(self.config, file.head(), self.csv_dialect)
  File "/usr/lib/python3/dist-packages/beancount/ingest/importers/csv.py", line 324, in normalize_config
    has_header = csv.Sniffer().has_header(head)
  File "/usr/lib/python3.7/csv.py", line 394, in has_header
    rdr = reader(StringIO(sample), self.sniff(sample))
  File "/usr/lib/python3.7/csv.py", line 188, in sniff
    raise Error("Could not determine delimiter")
_csv.Error: Could not determine delimiter

;; -*- mode: org; mode: beancount; coding: utf-8; -*-


The csv file looks pretty normal, it looks like this:

Stage,Transaction Date,Posted Date,Card No.,Description,Debit,Credit
POSTED,2019-02-09,2019-02-11,4524,PHARMAPRIX #0029         MONTREAL      QC,14.69
POSTED,2019-02-09,2019-02-11,4524,RACHELLE-BERY #8617      MONTREAL      QC,80.95

etc.

My __init__.py looks like this:

#!/usr/bin/env python3
from beancount.ingest import regression
from beancount.ingest.importers import csv

from beancount.plugins import auto_accounts


class Importer(csv.Importer):

    config = {csv.Col.DATE: 'Posted Date',
              csv.Col.TXN_DATE: 'Transaction Date',
              csv.Col.NARRATION: 'Description',
              csv.Col.AMOUNT_CREDIT: 'Credit',
              csv.Col.AMOUNT_DEBIT: 'Debit'}

    def __init__(self, account):
        csv.Importer.__init__(
            self, self.config,
            account, 'CAD',
            ('Stage,Transaction Date,Posted Date,Card No.,Description,'
             'Debit,Credit'),
            1)

    def get_description(self, row):
        payee, narration = super().get_description()
        narration = '{} ({})'.format(narration, row.category)
        return payee, narration


Is there something I'm missing here?

Thanks! 
crust

Martin Blais

unread,
Feb 17, 2019, 3:36:24 PM2/17/19
to Beancount
Your CSV file looks normal.
The CSV sniffer - the piece of code which attempts to automatically detect the dialect / separator from a CSV file contents - fails, for some reason I'm not familiar with.
Try specifying the delimiter explicitly.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/4073e7ff-1da6-42d1-8808-40e8dcce6951%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Blais

unread,
Feb 17, 2019, 3:40:21 PM2/17/19
to Beancount
I just noticed the csv.py code doesn't allow that.
Let me add an option real quick.

Martin Blais

unread,
Feb 17, 2019, 3:46:05 PM2/17/19
to Beancount
Actually, no, that won't change anything. The delimiter is a parameter of the dialect.
Using the 'excel' dialect (the default) should just work.
Check the arguments you provide to the csv importer against your version.
I'm not sure what the problem is.


Reply all
Reply to author
Forward
0 new messages