PYield 0.2.12__tar.gz → 0.2.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyield-0.2.12 → pyield-0.2.14}/PKG-INFO +1 -1
- pyield-0.2.14/pyield/__about__.py +1 -0
- {pyield-0.2.12 → pyield-0.2.14}/pyield/di_futures.py +2 -2
- pyield-0.2.12/pyield/di_html.py → pyield-0.2.14/pyield/di_url.py +1 -1
- {pyield-0.2.12 → pyield-0.2.14}/pyield/di_xml.py +8 -3
- {pyield-0.2.12 → pyield-0.2.14}/pyproject.toml +1 -1
- {pyield-0.2.12 → pyield-0.2.14}/tests/test_di.py +9 -4
- pyield-0.2.12/pyield/__about__.py +0 -1
- {pyield-0.2.12 → pyield-0.2.14}/LICENSE +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/README.md +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/pyield/__init__.py +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/pyield/br_calendar.py +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/pyield/new_br_holidays.txt +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/pyield/old_br_holidays.txt +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/tests/__init__.py +0 -0
- {pyield-0.2.12 → pyield-0.2.14}/tests/test_br_calendar.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.14"
|
|
@@ -2,7 +2,7 @@ from typing import Literal
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
import pandas as pd
|
|
4
4
|
|
|
5
|
-
from . import
|
|
5
|
+
from . import di_url
|
|
6
6
|
from . import di_xml
|
|
7
7
|
from . import br_calendar as bc
|
|
8
8
|
|
|
@@ -109,7 +109,7 @@ def get_di(
|
|
|
109
109
|
if source_type == "xml":
|
|
110
110
|
df = di_xml.get_di(reference_date, data_path, return_raw)
|
|
111
111
|
elif source_type == "html":
|
|
112
|
-
df =
|
|
112
|
+
df = di_url.get_di(reference_date, return_raw)
|
|
113
113
|
else:
|
|
114
114
|
raise ValueError("source_type must be either 'xml' or 'html'.")
|
|
115
115
|
|
|
@@ -112,7 +112,7 @@ def get_raw_di(reference_date: str | pd.Timestamp) -> pd.DataFrame:
|
|
|
112
112
|
|
|
113
113
|
except Exception as e:
|
|
114
114
|
warnings.warn(
|
|
115
|
-
f"A {type(e).__name__} occurred while reading the DI futures data for {reference_date.strftime(
|
|
115
|
+
f"A {type(e).__name__} occurred while reading the DI futures data for {reference_date.strftime('%d/%m/%Y')}. Returning an empty DataFrame."
|
|
116
116
|
)
|
|
117
117
|
return pd.DataFrame()
|
|
118
118
|
|
|
@@ -34,14 +34,19 @@ def extract_xml_file(zip_file: io.BytesIO) -> io.BytesIO:
|
|
|
34
34
|
|
|
35
35
|
# Then, read the inner file
|
|
36
36
|
with zipfile.ZipFile(outer_file, "r") as inner_zip:
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
filenames = inner_zip.namelist()
|
|
38
|
+
# Get first file that ends with ".xml"
|
|
39
|
+
xml_filename = [name for name in filenames if name.endswith(".xml")][0]
|
|
40
|
+
inner_file_content = inner_zip.read(xml_filename)
|
|
39
41
|
|
|
40
42
|
return io.BytesIO(inner_file_content)
|
|
41
43
|
|
|
42
44
|
|
|
43
45
|
def parse_xml_file(xml_file: io.BytesIO) -> list:
|
|
44
|
-
|
|
46
|
+
parser = etree.XMLParser(
|
|
47
|
+
ns_clean=True, remove_blank_text=True, remove_comments=True, recover=True
|
|
48
|
+
)
|
|
49
|
+
tree = etree.parse(xml_file, parser)
|
|
45
50
|
# Definir os namespaces (substitua 'ns' pelo prefixo apropriado se necessário)
|
|
46
51
|
namespaces = {"ns": "urn:bvmf.217.01.xsd"}
|
|
47
52
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import pandas as pd
|
|
2
2
|
|
|
3
3
|
from pyield import di_futures as dif
|
|
4
|
-
from pyield import
|
|
4
|
+
from pyield import di_url as diu
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
def test_valid_old_contract_code1():
|
|
8
8
|
contact_code = "JAN3" # Valid contract code
|
|
9
9
|
reference_date = pd.Timestamp("2001-05-21")
|
|
10
|
-
result =
|
|
10
|
+
result = diu.get_old_expiration_date(contact_code, reference_date)
|
|
11
11
|
contract_expiration = pd.Timestamp("2003-01-02")
|
|
12
12
|
assert result == contract_expiration
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ def test_valid_old_contract_code1():
|
|
|
15
15
|
def test_valid_old_contract_code2():
|
|
16
16
|
contact_code = "JAN3" # Valid contract code
|
|
17
17
|
reference_date = pd.Timestamp("1990-01-01")
|
|
18
|
-
result =
|
|
18
|
+
result = diu.get_old_expiration_date(contact_code, reference_date)
|
|
19
19
|
contract_expiration = pd.Timestamp("1993-01-04")
|
|
20
20
|
assert result == contract_expiration
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ def test_invalid_old_contract_code():
|
|
|
24
24
|
contact_code = "J3" # Invalid contract code
|
|
25
25
|
reference_date = pd.Timestamp("2001-01-02")
|
|
26
26
|
# Must return NaT
|
|
27
|
-
result =
|
|
27
|
+
result = diu.get_old_expiration_date(contact_code, reference_date)
|
|
28
28
|
assert pd.isnull(result)
|
|
29
29
|
|
|
30
30
|
|
|
@@ -71,3 +71,8 @@ def test_settlement_rates_with_current_holiday_list():
|
|
|
71
71
|
contract_codes = list(settlement_rates.keys()) # noqa: F841
|
|
72
72
|
results = df.query("contract_code in @contract_codes")["settlement_rate"].to_list()
|
|
73
73
|
assert results == list(settlement_rates.values())
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_invalid_date():
|
|
77
|
+
result = dif.get_di(reference_date="2023-12-24")
|
|
78
|
+
assert result.empty
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.12"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|