Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pandas support #14

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions demo/personal_finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,21 @@
assert ledger.get_account_balance('LOANS') == 1000
assert ledger.get_account_balance('SAVINGS_BANK') == 4000

# get pandas dataframe
ledger.get_df()
'''
sl_no account dr_amount ... date narration key
0 0 SAVINGS_BANK 20000 ... 2022-04-30 March salary person1
1 1 SALARY 0 ... 2022-04-30 March salary person1
2 2 MUTUAL_FUNDS 10000 ... 2022-05-01 Invest in NIFTY 50 Index person1
3 3 SAVINGS_BANK 0 ... 2022-05-01 Invest in NIFTY 50 Index person1
4 4 CAR_EMI 5000 ... 2022-05-05 5th EMI person1
5 5 SAVINGS_BANK 0 ... 2022-05-05 5th EMI person1
6 6 LOANS 3000 ... 2022-05-05 Lend to Kalyan person1
7 7 SAVINGS_BANK 0 ... 2022-05-05 Lend to Kalyan person1
8 8 SAVINGS_BANK 2000 ... 2022-05-15 Partial payback person1
9 9 LOANS 0 ... 2022-05-15 Partial payback person1

[10 rows x 7 columns]
'''

# get the balance sheet
ledger.get_balance_sheet()
'''
sl_no account dr_amount ... MUTUAL_FUNDS LOANS CAR_EMI
0 0 SAVINGS_BANK 20000 ... 0 0 0
1 1 SALARY 0 ... 0 0 0
2 2 MUTUAL_FUNDS 10000 ... 10000 0 0
3 3 SAVINGS_BANK 0 ... 10000 0 0
4 4 CAR_EMI 5000 ... 10000 0 5000
5 5 SAVINGS_BANK 0 ... 10000 0 5000
6 6 LOANS 3000 ... 10000 3000 5000
7 7 SAVINGS_BANK 0 ... 10000 3000 5000
8 8 SAVINGS_BANK 2000 ... 10000 3000 5000
9 9 LOANS 0 ... 10000 1000 5000
[
{'sl_no': 0, 'account': 'SAVINGS_BANK', 'dr_amount': 20000, 'cr_amount': 0, 'date': datetime.datetime(2022, 4, 30, 0, 0), 'narration': 'March salary', 'key': 'person1', 'SALARY': 0, 'SAVINGS_BANK': 20000, 'MUTUAL_FUNDS': 0, 'LOANS': 0, 'CAR_EMI': 0},
{'sl_no': 1, 'account': 'SALARY', 'dr_amount': 0, 'cr_amount': 20000, 'date': datetime.datetime(2022, 4, 30, 0, 0), 'narration': 'March salary', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 20000, 'MUTUAL_FUNDS': 0, 'LOANS': 0, 'CAR_EMI': 0},
{'sl_no': 2, 'account': 'MUTUAL_FUNDS', 'dr_amount': 10000, 'cr_amount': 0, 'date': datetime.datetime(2022, 5, 1, 0, 0), 'narration': 'Invest in NIFTY 50 Index', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 20000, 'MUTUAL_FUNDS': 10000, 'LOANS': 0, 'CAR_EMI': 0},
{'sl_no': 3, 'account': 'SAVINGS_BANK', 'dr_amount': 0, 'cr_amount': 10000, 'date': datetime.datetime(2022, 5, 1, 0, 0), 'narration': 'Invest in NIFTY 50 Index', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 10000, 'MUTUAL_FUNDS': 10000, 'LOANS': 0, 'CAR_EMI': 0},
{'sl_no': 4, 'account': 'CAR_EMI', 'dr_amount': 5000, 'cr_amount': 0, 'date': datetime.datetime(2022, 5, 5, 0, 0), 'narration': '5th EMI', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 10000, 'MUTUAL_FUNDS': 10000, 'LOANS': 0, 'CAR_EMI': 5000},
{'sl_no': 5, 'account': 'SAVINGS_BANK', 'dr_amount': 0, 'cr_amount': 5000, 'date': datetime.datetime(2022, 5, 5, 0, 0), 'narration': '5th EMI', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 5000, 'MUTUAL_FUNDS': 10000, 'LOANS': 0, 'CAR_EMI': 5000},
{'sl_no': 6, 'account': 'LOANS', 'dr_amount': 3000, 'cr_amount': 0, 'date': datetime.datetime(2022, 5, 5, 0, 0), 'narration': 'Lend to Kalyan', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 5000, 'MUTUAL_FUNDS': 10000, 'LOANS': 3000, 'CAR_EMI': 5000},
{'sl_no': 7, 'account': 'SAVINGS_BANK', 'dr_amount': 0, 'cr_amount': 3000, 'date': datetime.datetime(2022, 5, 5, 0, 0), 'narration': 'Lend to Kalyan', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 2000, 'MUTUAL_FUNDS': 10000, 'LOANS': 3000, 'CAR_EMI': 5000},
{'sl_no': 8, 'account': 'SAVINGS_BANK', 'dr_amount': 2000, 'cr_amount': 0, 'date': datetime.datetime(2022, 5, 15, 0, 0), 'narration': 'Partial payback', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 4000, 'MUTUAL_FUNDS': 10000, 'LOANS': 3000, 'CAR_EMI': 5000},
{'sl_no': 9, 'account': 'LOANS', 'dr_amount': 0, 'cr_amount': 2000, 'date': datetime.datetime(2022, 5, 15, 0, 0), 'narration': 'Partial payback', 'key': 'person1', 'SALARY': 20000, 'SAVINGS_BANK': 4000, 'MUTUAL_FUNDS': 10000, 'LOANS': 1000, 'CAR_EMI': 5000}
]

[10 rows x 12 columns]
'''
Expand Down
18 changes: 0 additions & 18 deletions pyluca/balances.py

This file was deleted.

23 changes: 12 additions & 11 deletions pyluca/ledger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pandas as pd
from pyluca.account_config import BalanceType
from pyluca.aging import get_account_aging
from pyluca.balances import add_account_balance
from pyluca.journal import Journal


Expand All @@ -22,17 +20,20 @@ def get_account_balance(self, account: str):
return self.get_account_dr(account) - self.get_account_cr(account)
return self.get_account_cr(account) - self.get_account_dr(account)

def get_df(self) -> pd.DataFrame:
return pd.DataFrame([j.__dict__ for j in self.journal.entries])

def get_aging(self, account: str):
return get_account_aging(self.config, self.journal.entries, account, self.journal.entries[-1].date)

def add_account_balance(self, account: str, df: pd.DataFrame):
return add_account_balance(self.config, df, account)

def get_balance_sheet(self):
df = self.get_df()
ledger = [_entry.__dict__ for _entry in self.journal.entries]
for acct_name in self.config['accounts'].keys():
df = self.add_account_balance(acct_name, df)
return df
account_type = self.config['accounts'][acct_name]['type']
positive_col, negative_col = 'cr_amount', 'dr_amount'
if self.config['account_types'][account_type]['balance_type'] == BalanceType.DEBIT.value:
positive_col, negative_col = 'dr_amount', 'cr_amount'
balance = 0
for row in ledger:
if row['account'] == acct_name:
balance += row[positive_col]
balance -= row[negative_col]
row[acct_name] = balance
return ledger
1 change: 0 additions & 1 deletion pyluca/tests/test_accountant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_base(self):
ledger = Ledger(accountant.journal, accountant.config)
self.assertEqual(ledger.get_account_balance('SAVINGS_BANK'), 20000)
self.assertEqual(ledger.get_account_balance('SALARY'), 20000)
self.assertEqual(len(ledger.get_df()), 2)

accountant.enter_journal('MUTUAL_FUNDS', 'SAVINGS_BANK', 10000, datetime(2022, 5, 1), 'ELSS')
ledger = Ledger(accountant.journal, accountant.config)
Expand Down
2 changes: 1 addition & 1 deletion pyluca/tests/test_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_ledger_balance_sheet(self):
accountant.enter_journal('LOANS', 'SAVINGS_BANK', 5000, datetime(2022, 5, 2), 'Lend to Pramod')
accountant.enter_journal('CAR_EMI', 'SAVINGS_BANK', 3000, datetime(2022, 5, 2), 'EMI 3/48')
ledger = Ledger(accountant.journal, account_config)
last_row = ledger.get_balance_sheet().to_dict(orient='record')[-1]
last_row = ledger.get_balance_sheet()[-1]
self.assertEqual(last_row['SALARY'], 20000)
self.assertEqual(last_row['SAVINGS_BANK'], 2000)
self.assertEqual(last_row['MUTUAL_FUNDS'], 10000)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
pandas==1.1.5
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name='pyluca',
version='0.0.7',
version='0.0.8',
author='datasignstech',
author_email='tech+opensource@datasignstech.com',
description='Double entry accounting system',
Expand Down