numbers-parser 4.13.3__py3-none-any.whl → 4.14.2__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.
@@ -1,8 +1,9 @@
1
1
  from collections import OrderedDict
2
+ from datetime import datetime
2
3
  from enum import IntEnum
4
+ from math import ceil
3
5
 
4
6
  import enum_tools.documentation
5
- from pendulum import datetime
6
7
 
7
8
  try:
8
9
  from importlib.resources import files
@@ -64,7 +65,7 @@ DOCUMENT_ID = 1
64
65
  PACKAGE_ID = 2
65
66
 
66
67
  # System constants
67
- EPOCH = datetime(2001, 1, 1)
68
+ EPOCH = datetime(2001, 1, 1) # noqa: DTZ001
68
69
  SECONDS_IN_HOUR = 60 * 60
69
70
  SECONDS_IN_DAY = SECONDS_IN_HOUR * 24
70
71
  SECONDS_IN_WEEK = SECONDS_IN_DAY * 7
@@ -89,6 +90,7 @@ SUPPORTED_NUMBERS_VERSIONS = [
89
90
  "14.0",
90
91
  "14.1",
91
92
  "14.2",
93
+ "14.3",
92
94
  ]
93
95
 
94
96
 
@@ -99,6 +101,16 @@ def _days_occurred_in_month(value: datetime) -> str:
99
101
  return str(n_days)
100
102
 
101
103
 
104
+ def _day_of_year(value: datetime) -> int:
105
+ """Return the day number in a year for a datetime."""
106
+ return value.timetuple().tm_yday
107
+
108
+
109
+ def _week_of_month(value: datetime) -> int:
110
+ """Return the week number in a month for a datetime."""
111
+ return int(ceil((value.day + value.replace(day=1).weekday()) / 7.0))
112
+
113
+
102
114
  DATETIME_FIELD_MAP = OrderedDict(
103
115
  [
104
116
  ("a", lambda x: x.strftime("%p").lower()),
@@ -113,9 +125,9 @@ DATETIME_FIELD_MAP = OrderedDict(
113
125
  ("M", "%-m"),
114
126
  ("d", "%-d"),
115
127
  ("dd", "%d"),
116
- ("DDD", lambda x: str(x.day_of_year).zfill(3)),
117
- ("DD", lambda x: str(x.day_of_year).zfill(2)),
118
- ("D", lambda x: str(x.day_of_year).zfill(1)),
128
+ ("DDD", lambda x: str(_day_of_year(x)).zfill(3)),
129
+ ("DD", lambda x: str(_day_of_year(x)).zfill(2)),
130
+ ("D", lambda x: str(_day_of_year(x)).zfill(1)),
119
131
  ("HH", "%H"),
120
132
  ("H", "%-H"),
121
133
  ("hh", "%I"),
@@ -128,7 +140,7 @@ DATETIME_FIELD_MAP = OrderedDict(
128
140
  ("m", lambda x: str(x.minute)),
129
141
  ("ss", "%S"),
130
142
  ("s", lambda x: str(x.second)),
131
- ("W", lambda x: str(x.week_of_month - 1)),
143
+ ("W", lambda x: str(_week_of_month(x) - 1)),
132
144
  ("ww", "%W"),
133
145
  ("G", "AD"), # TODO: support BC
134
146
  ("F", lambda x: _days_occurred_in_month(x)),
@@ -258,7 +270,8 @@ CUSTOM_FORMATTING_ALLOWED_CELLS = {
258
270
 
259
271
  @enum_tools.documentation.document_enum
260
272
  class NegativeNumberStyle(IntEnum):
261
- """How negative numbers are formatted.
273
+ """
274
+ How negative numbers are formatted.
262
275
 
263
276
  This enum is used in cell data formats and cell custom formats using the
264
277
  `negative_style` keyword argument.
@@ -276,7 +289,8 @@ class NegativeNumberStyle(IntEnum):
276
289
 
277
290
  @enum_tools.documentation.document_enum
278
291
  class FractionAccuracy(IntEnum):
279
- """How fractions are formatted.
292
+ """
293
+ How fractions are formatted.
280
294
 
281
295
  This enum is used in cell data formats and cell custom formats using the
282
296
  `fraction_accuracy` keyword argument.
@@ -10,7 +10,7 @@ from numbers_parser.iwork import IWork, IWorkHandler
10
10
  class ItemsList:
11
11
  def __init__(self, model, refs, item_class) -> None:
12
12
  self._item_name = item_class.__name__.lower()
13
- self._items = [item_class(model, id) for id in refs]
13
+ self._items = [item_class(model, x) for x in refs]
14
14
 
15
15
  def __getitem__(self, key: int):
16
16
  if isinstance(key, int):
@@ -20,16 +20,15 @@ class ItemsList:
20
20
  msg = f"index {key} out of range"
21
21
  raise IndexError(msg)
22
22
  return self._items[key]
23
- elif isinstance(key, str):
23
+ if isinstance(key, str):
24
24
  for item in self._items:
25
25
  if item.name == key:
26
26
  return item
27
27
  msg = f"no {self._item_name} named '{key}'"
28
28
  raise KeyError(msg)
29
- else:
30
- t = type(key).__name__
31
- msg = f"invalid index type {t}"
32
- raise LookupError(msg)
29
+ t = type(key).__name__
30
+ msg = f"invalid index type {t}"
31
+ raise LookupError(msg)
33
32
 
34
33
  def __len__(self) -> int:
35
34
  return len(self._items)
@@ -37,7 +36,7 @@ class ItemsList:
37
36
  def __contains__(self, key) -> bool:
38
37
  return key.lower() in [x.name.lower() for x in self._items]
39
38
 
40
- def append(self, item):
39
+ def append(self, item) -> None:
41
40
  self._items.append(item)
42
41
 
43
42
 
@@ -79,7 +78,8 @@ class ObjectStore(IWorkHandler):
79
78
  return self._max_id
80
79
 
81
80
  def create_object_from_dict(self, iwa_file: str, object_dict: dict, cls: object, append=False):
82
- """Create a new object and store the associated IWA segment. Return the
81
+ """
82
+ Create a new object and store the associated IWA segment. Return the
83
83
  message ID for the object and the newly created object. If the IWA
84
84
  file cannot be found, it will be created.
85
85
  """
@@ -100,8 +100,9 @@ class ObjectStore(IWorkHandler):
100
100
  self._object_to_filename_map[new_id] = iwa_pathname
101
101
  return new_id, self._objects[new_id]
102
102
 
103
- def update_object_file_store(self):
104
- """Copy the protobuf messages from any updated object to the cached
103
+ def update_object_file_store(self) -> None:
104
+ """
105
+ Copy the protobuf messages from any updated object to the cached
105
106
  version in the file store so this can be saved to a new document.
106
107
  """
107
108
  for obj_id in self._objects: