datedict 0.1.6__tar.gz → 0.1.7__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.
Potentially problematic release.
This version of datedict might be problematic. Click here for more details.
- {datedict-0.1.6 → datedict-0.1.7}/PKG-INFO +1 -1
- {datedict-0.1.6 → datedict-0.1.7}/pyproject.toml +1 -1
- {datedict-0.1.6 → datedict-0.1.7}/src/datedict/DateDict.py +31 -17
- {datedict-0.1.6 → datedict-0.1.7}/.gitignore +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/.gitlab-ci.yml +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/LICENSE +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/README.md +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/pytest.ini +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/src/datedict/YearDict.py +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/src/datedict/__init__.py +0 -0
- {datedict-0.1.6 → datedict-0.1.7}/src/datedict/common.py +0 -0
|
@@ -27,21 +27,24 @@ class DateDict:
|
|
|
27
27
|
self.start_date, self.end_date = dates[0], dates[-1]
|
|
28
28
|
self.data: dict[str, Decimal] = {k: to_decimal(v) for k, v in data.items()}
|
|
29
29
|
|
|
30
|
-
def fill(
|
|
30
|
+
def fill(
|
|
31
|
+
self, start_date: str | date, end_date: str | date, value: Decimable
|
|
32
|
+
) -> "DateDict":
|
|
31
33
|
"""
|
|
32
34
|
Create a new graph with a specified range and value.
|
|
33
35
|
The range is defined by start_date and end_date.
|
|
34
36
|
"""
|
|
37
|
+
start = (
|
|
38
|
+
start_date
|
|
39
|
+
if isinstance(start_date, date)
|
|
40
|
+
else date.fromisoformat(start_date)
|
|
41
|
+
)
|
|
42
|
+
end = end_date if isinstance(end_date, date) else date.fromisoformat(end_date)
|
|
35
43
|
v = to_decimal(value)
|
|
36
44
|
return DateDict(
|
|
37
45
|
{
|
|
38
|
-
(
|
|
39
|
-
|
|
40
|
-
): v
|
|
41
|
-
for i in range(
|
|
42
|
-
(date.fromisoformat(end_date) - date.fromisoformat(start_date)).days
|
|
43
|
-
+ 1
|
|
44
|
-
)
|
|
46
|
+
(start + timedelta(days=i)).strftime("%Y-%m-%d"): v
|
|
47
|
+
for i in range((end - start).days + 1)
|
|
45
48
|
}
|
|
46
49
|
)
|
|
47
50
|
|
|
@@ -118,25 +121,36 @@ class DateDict:
|
|
|
118
121
|
)
|
|
119
122
|
|
|
120
123
|
def sum(
|
|
121
|
-
self: "DateDict",
|
|
124
|
+
self: "DateDict",
|
|
125
|
+
start_date: str | date | None = None,
|
|
126
|
+
end_date: str | date | None = None,
|
|
122
127
|
) -> Decimal:
|
|
123
128
|
"""
|
|
124
129
|
Return the sum of values in the specified range.
|
|
125
130
|
If a value is NaN, it is treated as zero.
|
|
126
131
|
"""
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
start = (
|
|
133
|
+
date.fromisoformat(self.start_date)
|
|
134
|
+
if start_date is None
|
|
135
|
+
else (
|
|
136
|
+
start_date
|
|
137
|
+
if isinstance(start_date, date)
|
|
138
|
+
else date.fromisoformat(start_date)
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
end = (
|
|
142
|
+
date.fromisoformat(self.end_date)
|
|
143
|
+
if end_date is None
|
|
144
|
+
else (
|
|
145
|
+
end_date if isinstance(end_date, date) else date.fromisoformat(end_date)
|
|
146
|
+
)
|
|
147
|
+
)
|
|
129
148
|
return sum(
|
|
130
149
|
[
|
|
131
150
|
(self.get(k, ZERO))
|
|
132
151
|
for k in map(
|
|
133
152
|
lambda x: x.strftime("%Y-%m-%d"),
|
|
134
|
-
[
|
|
135
|
-
date.fromisoformat(s) + timedelta(days=i)
|
|
136
|
-
for i in range(
|
|
137
|
-
(date.fromisoformat(e) - date.fromisoformat(s)).days + 1
|
|
138
|
-
)
|
|
139
|
-
],
|
|
153
|
+
[start + timedelta(days=i) for i in range((end - start).days + 1)],
|
|
140
154
|
)
|
|
141
155
|
],
|
|
142
156
|
ZERO,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|