Support CSV files where the amount isn't in a single column and the value embeds currency symbol
Support use cases where the CSV file doesn't have amount in a single column---instead the amount is derived from multiple columns. In my case (see unit test case test_extract_amount), the bank's CSV had a "Withdrawal" column and a "Deposit" column. In each row, only one on those columns has a positive numeric value.
Furthermore, the numeric value embeds currency ('$') symbol with comma separated digits that were not being parsed correctly.
Thanks for your contribution. I haven't had a close look yet. However, the idea behind the csvbase module is to provide an extensible base for writing importers dealing with CSV files, not to provide configuration knobs for every possible case. The latter causes combinatorial explosion of complexity and configurations that need to be tested, which is the main motivation for replacing beanqulp.importers.csv with beangulp.importers.csvbase. Therefore, if it exists a way to solve the problem that avoid adding complexity to the base class, it should be preferred to extending the base classes. I'll have a closer look and I'll let you know.
This should work for your use case:
from beangulp.importers import csvbase
from beangulp.utils import parse_amount
class WithdrawalOrDeposit(csvbase.Column):
def __init__(self, withdrawal, deposit):
super().__init__(withdrawal, deposit)
def parse(self, withdrawal, deposit):
if withdrawal and deposit:
raise ValueError
return -parse_amount(withdrawal) if withdrawal else parse_amount(deposit)
class Importer(csvbase.Importer):
date = csvbase.Date('Date', '%m/%d/%Y')
narration = csvbase.Columns('Description')
amount = WithdrawalOrDeposit('Withdrawal', 'Deposit')
No contributor responses to review in a few months. Closing