File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99)
1010import pandas as pd
1111
12-
1312OLINDA_BASE_URL = "https://olinda.bcb.gov.br/olinda/servico"
1413
1514
@@ -30,9 +29,19 @@ def __call__(self, *args):
3029
3130
3231class EndpointQuery (ODataQuery ):
32+ _DATE_COLUMN_NAMES = {
33+ "Data" ,
34+ "DataReferencia" ,
35+ }
36+
3337 def collect (self ):
34- data = super ().collect ()
35- return pd .DataFrame (data ["value" ])
38+ raw_data = super ().collect ()
39+ data = pd .DataFrame (raw_data ["value" ])
40+ for col in self ._DATE_COLUMN_NAMES :
41+ if col not in data .columns :
42+ continue
43+ data [col ] = pd .to_datetime (data [col ])
44+ return data
3645
3746
3847class Endpoint (metaclass = EndpointMeta ):
Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ matplotlib = "^3.5.3"
2424ipython = " ^8.14.0"
2525furo = " ^2022.6.21"
2626
27-
2827[tool .poetry .group .dev .dependencies ]
2928pycodestyle = " ^2.9.1"
3029ipykernel = " ^6.15.2"
Original file line number Diff line number Diff line change 1+ import pandas as pd
2+ from datetime import datetime
3+ from pytest import fixture
4+
5+ from bcb import Expectativas
6+
7+
8+ @fixture
9+ def endpoints ():
10+ ep = Expectativas ()
11+ return [ep .get_endpoint (e .data ["name" ]) for e in ep .service .endpoints ]
12+
13+
14+ def test_expectativas_date_format (endpoints ):
15+ for endpoint in endpoints :
16+ query = endpoint .query ().limit (1 )
17+ data = query .collect ()
18+ assert isinstance (data , pd .DataFrame )
19+ assert data .shape [0 ] == 1
20+ assert isinstance (data ["Data" ].iloc [0 ], datetime )
21+ if "DataReferencia" in data .columns :
22+ assert isinstance (data ["DataReferencia" ].iloc [0 ], datetime )
You can’t perform that action at this time.
0 commit comments