datedict 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

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/DateDict.py CHANGED
@@ -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(self, start_date, end_date, value: Decimable) -> "DateDict":
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
- (date.fromisoformat(start_date) + timedelta(days=i)).strftime(
39
- "%Y-%m-%d"
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", start: str | None = None, end: str | None = None
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
- s = self.start_date if start is None else start
128
- e = self.end_date if end is None else end
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datedict
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: DateDict and YearDict: date-aware dictionary structures
5
5
  Project-URL: Homepage, https://gitlab.com/grisus/datedict
6
6
  Project-URL: Issues, https://gitlab.com/grisus/datedict/-/issues
@@ -0,0 +1,8 @@
1
+ datedict/DateDict.py,sha256=2iTPwp81PA-ni-FJW-Ok-G7wiOJBxyJST4dwrJoWIpE,8129
2
+ datedict/YearDict.py,sha256=avVXgCp_zgSL5khqCjR6Z5vh-vqFwEdK-5TO9wfhjfc,5493
3
+ datedict/__init__.py,sha256=4QSCqCW_owSqD3k3Oz1WAsB4p_vvzUlINroAxxFCEWQ,201
4
+ datedict/common.py,sha256=aUCsMV6roKGQIQXSFIJIN0cxAXIlK_YyRDWS1EIBu8E,424
5
+ datedict-0.1.7.dist-info/METADATA,sha256=m0njoUnyNurBSPquzGFjYvYpKcmAKhTIWtVOHD5mAe0,1991
6
+ datedict-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ datedict-0.1.7.dist-info/licenses/LICENSE,sha256=GMmiaNfJSsljmGtIp9lCY6V-Dkc9NDZn0jSZuAbFe7Y,1070
8
+ datedict-0.1.7.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- datedict/DateDict.py,sha256=DdzGhURzOOE13GvNHoKQ28bb-crgE3bGhtUqjaok23Y,7775
2
- datedict/YearDict.py,sha256=avVXgCp_zgSL5khqCjR6Z5vh-vqFwEdK-5TO9wfhjfc,5493
3
- datedict/__init__.py,sha256=4QSCqCW_owSqD3k3Oz1WAsB4p_vvzUlINroAxxFCEWQ,201
4
- datedict/common.py,sha256=aUCsMV6roKGQIQXSFIJIN0cxAXIlK_YyRDWS1EIBu8E,424
5
- datedict-0.1.6.dist-info/METADATA,sha256=2toUqZh5PzbRriZJiFYEimotLxkZLHU0OxvWGRY8YZY,1991
6
- datedict-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- datedict-0.1.6.dist-info/licenses/LICENSE,sha256=GMmiaNfJSsljmGtIp9lCY6V-Dkc9NDZn0jSZuAbFe7Y,1070
8
- datedict-0.1.6.dist-info/RECORD,,