Skip to content

Commit d3fe083

Browse files
committed
Fix detection by region and add more codes from the north region
1 parent c180548 commit d3fe083

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

bcb/sgs/regional_economy.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pandas as pd
33

44
NON_PERFORMING_LOANS_BY_REGION_PF = {
5-
"N": "",
5+
"N": "15888",
66
"NE": "",
77
"CO": "",
88
"SE": "",
@@ -30,25 +30,25 @@
3030
"RJ": "",
3131
"RN": "",
3232
"RS": "",
33-
"RO": "",
34-
"RR": "",
33+
"RO": "15882",
34+
"RR": "15883",
3535
"SC": "",
3636
"SP": "",
3737
"SE": "",
38-
"TO": "",
38+
"TO": "15887",
3939
}
4040
NON_PERFORMING_LOANS_BY_REGION_PJ = {
41-
"N": "",
41+
"N": "15920",
4242
"NE": "",
4343
"CO": "",
4444
"SE": "",
4545
"S": "",
4646
}
4747
NON_PERFORMING_LOANS_BY_STATE_PJ = {
48-
"AC": "15861",
48+
"AC": "15893",
4949
"AL": "",
50-
"AP": "15863",
51-
"AM": "15864",
50+
"AP": "15895",
51+
"AM": "15896",
5252
"BA": "15865",
5353
"CE": "",
5454
"DF": "",
@@ -58,33 +58,33 @@
5858
"MT": "",
5959
"MS": "",
6060
"MG": "",
61-
"PA": "15874",
61+
"PA": "15906",
6262
"PB": "",
6363
"PR": "",
6464
"PE": "",
6565
"PI": "",
6666
"RJ": "",
6767
"RN": "",
6868
"RS": "",
69-
"RO": "",
70-
"RR": "",
69+
"RO": "15914",
70+
"RR": "15915",
7171
"SC": "",
7272
"SP": "",
7373
"SE": "",
74-
"TO": ""
74+
"TO": "15919"
7575
}
7676
NON_PERFORMING_LOANS_BY_REGION_TOTAL = {
77-
"N": "",
77+
"N": "15952",
7878
"NE": "",
7979
"CO": "",
8080
"SE": "",
8181
"S": "",
8282
}
8383
NON_PERFORMING_LOANS_BY_STATE_TOTAL = {
84-
"AC": "15861",
84+
"AC": "15925",
8585
"AL": "",
86-
"AP": "15863",
87-
"AM": "15864",
86+
"AP": "15927",
87+
"AM": "15928",
8888
"BA": "15865",
8989
"CE": "",
9090
"DF": "",
@@ -94,56 +94,55 @@
9494
"MT": "",
9595
"MS": "",
9696
"MG": "",
97-
"PA": "15874",
97+
"PA": "15938",
9898
"PB": "",
9999
"PR": "",
100100
"PE": "",
101101
"PI": "",
102102
"RJ": "",
103103
"RN": "",
104104
"RS": "",
105-
"RO": "",
106-
"RR": "",
105+
"RO": "15946",
106+
"RR": "15947",
107107
"SC": "",
108108
"SP": "",
109109
"SE": "",
110-
"TO": ""
110+
"TO": "15951"
111111
}
112112

113113

114114
def get_non_performing_loans_codes(states_or_region, mode="total"):
115115
"""SGS da Inadimplência das operações de crédito.
116116
117117
Pode ser total, pessoas físicas (PF) ou jurídicas (PJ)."""
118-
non_performing_loans_by_state = NON_PERFORMING_LOANS_BY_STATE_TOTAL
119-
non_performing_loans_by_region = NON_PERFORMING_LOANS_BY_REGION_TOTAL
120-
121118
is_state = False
122119
is_region = False
123120
states_or_region = [states_or_region] if isinstance(states_or_region, str) else states_or_region
124121
states_or_region = [location.upper() for location in states_or_region]
125-
if any(location in list(non_performing_loans_by_state.keys()) for location in states_or_region):
122+
if any(location in list(NON_PERFORMING_LOANS_BY_STATE_TOTAL.keys()) for location in states_or_region):
126123
is_state = True
127-
elif any(location in list(non_performing_loans_by_region.keys()) for location in states_or_region):
124+
elif any(location in list(NON_PERFORMING_LOANS_BY_REGION_TOTAL.keys()) for location in states_or_region):
128125
is_region = True
129126

130127
if not is_state and not is_region:
131128
raise Exception(f"Not a valid state or region: {states_or_region}")
132129

133130
codes = []
131+
non_performing_loans_by_location = NON_PERFORMING_LOANS_BY_STATE_TOTAL
134132
if is_state:
135133
if mode.upper() == "PF":
136-
non_performing_loans_by_state = NON_PERFORMING_LOANS_BY_STATE_PF
134+
non_performing_loans_by_location = NON_PERFORMING_LOANS_BY_STATE_PF
137135
elif mode.upper() == "PJ":
138-
non_performing_loans_by_state = NON_PERFORMING_LOANS_BY_STATE_PJ
136+
non_performing_loans_by_location = NON_PERFORMING_LOANS_BY_STATE_PJ
139137
elif is_region:
138+
non_performing_loans_by_location = NON_PERFORMING_LOANS_BY_REGION_TOTAL
140139
if mode.upper() == "PF":
141-
non_performing_loans_by_state = NON_PERFORMING_LOANS_BY_REGION_PF
140+
non_performing_loans_by_location = NON_PERFORMING_LOANS_BY_REGION_PF
142141
elif mode.upper() == "PJ":
143-
non_performing_loans_by_state = NON_PERFORMING_LOANS_BY_REGION_PJ
142+
non_performing_loans_by_location = NON_PERFORMING_LOANS_BY_REGION_PJ
144143

145144
for location in states_or_region:
146-
codes.append(non_performing_loans_by_state.get(location))
145+
codes.append(non_performing_loans_by_location[location])
147146
return codes
148147

149148

tests/sgs/test_regional_economy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
class TestGetNonPerformingLoansCodes:
77
@pytest.mark.parametrize("states,expected_codes", [
8-
(["ba", "pa"], ["15865", "15874"]),
8+
(["ba", "pa"], ["15865", "15938"]),
99
(["BA"], ["15865"]),
10+
("N", ["15952"]),
1011
])
1112
def test_get_non_performing_loans_codes_by_state_total(self, states, expected_codes):
1213
assert get_non_performing_loans_codes(states) == expected_codes
@@ -16,10 +17,10 @@ class TestGetNonPerformingLoans:
1617
@pytest.mark.parametrize("states,expected_columns", [
1718
(["BA"], ["15865"]),
1819
(["ba"], ["15865"]),
19-
#(["ba", "se", "al"], ["1"])
20+
("N", ["15888"]),
2021
])
21-
def test_get_series_by_states(self, states, expected_columns):
22-
series = get_non_performing_loans(states, last=10)
22+
def test_get_series_by_states_pf(self, states, expected_columns):
23+
series = get_non_performing_loans(states, last=10, mode="pf")
2324
assert isinstance(series, pd.DataFrame)
2425
assert series.columns == expected_columns
2526
assert len(series) == 10

0 commit comments

Comments
 (0)