mergeron_extra 2024.739148.6__tar.gz → 2024.739148.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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: mergeron_extra
3
- Version: 2024.739148.6
3
+ Version: 2024.739148.7
4
4
  Summary: Tools for users of the mergeron package.
5
5
  License: MIT
6
6
  Author: Murthy Kambhampaty
@@ -4,7 +4,7 @@ description = "Tools for users of the mergeron package."
4
4
  authors = ["Murthy Kambhampaty <smk@capeconomics.com>"]
5
5
  license = "MIT"
6
6
  readme = "README.rst"
7
- version = "2024.739148.6"
7
+ version = "2024.739148.7"
8
8
 
9
9
  classifiers = [
10
10
  "Development Status :: 4 - Beta",
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import numpy as np
4
4
  from numpy.typing import NDArray
5
5
 
6
- VERSION = "2024.739148.6"
6
+ VERSION = "2024.739148.7"
7
7
 
8
8
  __version__ = VERSION
9
9
 
@@ -25,7 +25,7 @@ from __future__ import annotations
25
25
 
26
26
  from collections.abc import Sequence
27
27
  from types import MappingProxyType
28
- from typing import Any, ClassVar, Literal, TypeAlias, TypedDict
28
+ from typing import Any, ClassVar, Literal, TypeAlias, TypedDict, overload
29
29
 
30
30
  import numpy as np
31
31
  from aenum import Enum, extend_enum, unique # type: ignore
@@ -261,7 +261,7 @@ class CFmt(Enum): # type: ignore
261
261
  def xl_fmt(
262
262
  cls,
263
263
  _xl_book: Workbook,
264
- _cell_fmt: Sequence[CFmt | Sequence[CFmt]] | CFmt | None,
264
+ _cell_format: Sequence[CFmt | Sequence[CFmt]] | CFmt | None,
265
265
  /,
266
266
  ) -> Format:
267
267
  """
@@ -272,7 +272,7 @@ class CFmt(Enum): # type: ignore
272
272
  _xl_book
273
273
  :code:`xlsxwriter.Workbook` object
274
274
 
275
- _cell_fmt
275
+ _cell_format
276
276
  :class:`CFmt` enum object, or tuple thereof
277
277
 
278
278
  Raises
@@ -287,26 +287,26 @@ class CFmt(Enum): # type: ignore
287
287
 
288
288
  """
289
289
 
290
- if isinstance(_cell_fmt, Format):
291
- return _cell_fmt
292
- elif _cell_fmt is None:
290
+ if isinstance(_cell_format, Format):
291
+ return _cell_format
292
+ elif _cell_format is None:
293
293
  return _xl_book.add_format(CFmt.XL_DEFAULT.value)
294
294
 
295
- _cell_fmt_dict: CFmtVal = {}
296
- if isinstance(_cell_fmt, Sequence):
297
- cls.ensure_cell_format_spec_tuple(_cell_fmt)
298
- for _cf in _cell_fmt:
295
+ _cell_format_dict: CFmtVal = {}
296
+ if isinstance(_cell_format, Sequence):
297
+ cls.ensure_cell_format_spec_tuple(_cell_format)
298
+ for _cf in _cell_format:
299
299
  if isinstance(_cf, Sequence):
300
300
  for _cfi in _cf:
301
- _cell_fmt_dict |= _cfi.value
301
+ _cell_format_dict |= _cfi.value
302
302
  else:
303
- _cell_fmt_dict |= _cf.value
304
- elif isinstance(_cell_fmt, CFmt):
305
- _cell_fmt_dict = _cell_fmt.value
303
+ _cell_format_dict |= _cf.value
304
+ elif isinstance(_cell_format, CFmt):
305
+ _cell_format_dict = _cell_format.value
306
306
  else:
307
307
  raise ValueError("Improperly specified format specification.")
308
308
 
309
- return _xl_book.add_format(_cell_fmt_dict)
309
+ return _xl_book.add_format(_cell_format_dict)
310
310
 
311
311
 
312
312
  def write_header(
@@ -550,29 +550,57 @@ def array_to_sheet(
550
550
  return _bottom_row_id, _right_column_id
551
551
 
552
552
 
553
+ @overload
554
+ def scalar_to_sheet(
555
+ _xl_book: Workbook,
556
+ _xl_sheet: Worksheet,
557
+ _address0: str,
558
+ _value: Any,
559
+ _format: CFmt | Sequence[CFmt | Sequence[CFmt]] | None,
560
+ /,
561
+ ) -> None: ...
562
+
563
+
564
+ @overload
553
565
  def scalar_to_sheet(
554
566
  _xl_book: Workbook,
555
567
  _xl_sheet: Worksheet,
568
+ _address0: int,
569
+ _address1: int,
570
+ _value: Any,
571
+ _format: CFmt | Sequence[CFmt | Sequence[CFmt]] | None,
556
572
  /,
557
- *_s2s_args: tuple[str, Any, CFmt | Sequence[CFmt | Sequence[CFmt]] | None]
558
- | tuple[int, int, Any, CFmt | Sequence[CFmt | Sequence[CFmt]] | None],
573
+ ) -> None: ...
574
+
575
+
576
+ def scalar_to_sheet(
577
+ _xl_book: Workbook, _xl_sheet: Worksheet, /, *_s2s_args: Any
559
578
  ) -> None:
560
579
  """
561
580
  Write to a single cell in a worksheet.
562
581
 
563
582
  Parameters
564
583
  ----------
584
+ _xl_book
585
+ Workbook object for defining formats, and writing data
586
+
565
587
  _xl_sheet
566
- Worksheet object to which to write the give array
588
+ Worksheet object to which to write the given scalar
589
+
590
+ _cell_addr
591
+ An Excel cell address string in 'A1' format
592
+
593
+ _address0
594
+ Index-0 row number of destintaion cell
595
+
596
+ _address1
597
+ Index-0 column number of destintaion cell
567
598
 
568
- _cell_addr_0
569
- First element of a cell address, which may be the entire address
570
- in 'A1' format or the row-part in 'Row-column' format
599
+ _value
600
+ Value to write
571
601
 
572
- _s2s_args
573
- Other arguments, which may be just the cell value to be written and the
574
- cell format, or the column-part of the 'Row-column' address along with
575
- cell value and cell format.
602
+ _format
603
+ Member of :class:`CFmt`, or tuple thereof
576
604
 
577
605
  Raises
578
606
  ------
@@ -592,39 +620,42 @@ def scalar_to_sheet(
592
620
 
593
621
  """
594
622
 
595
- _cell_addr: tuple[str] | tuple[int, int]
596
- _cell_val: Any
597
- _cell_fmt: CFmt | Sequence[CFmt | Sequence[CFmt]] | None
623
+ _address: tuple[str] | tuple[int, int]
624
+ _value: Any
625
+ _format: CFmt | Sequence[CFmt | Sequence[CFmt]] | None
598
626
 
599
627
  if isinstance(_s2s_args[0], str):
600
628
  if len(_s2s_args) not in (2, 3):
601
629
  raise ValueError("Incorrect number of arguments.")
602
- _cell_addr = (_s2s_args[0],)
603
- _cell_val = _s2s_args[0]
604
- _cell_fmt = _s2s_args[1] if len(_s2s_args) == 2 else None
630
+ _address = (_s2s_args[0],)
631
+ _value = _s2s_args[1]
632
+ _format = _s2s_args[2] if len(_s2s_args) == 3 else None
605
633
  elif isinstance(_s2s_args[0], int):
606
634
  if not isinstance(_s2s_args[1], int) or len(_s2s_args) not in (3, 4):
607
635
  print(repr(_s2s_args))
608
636
  raise ValueError("Incorrect/incomplete specification for Excel cell data.")
609
- _cell_addr = _s2s_args[:2]
610
- _cell_val = _s2s_args[2]
611
- _cell_fmt = _s2s_args[3] if len(_s2s_args) == 3 else None
637
+ _address = _s2s_args[:2]
638
+ _value = _s2s_args[2]
639
+ _format = _s2s_args[3] if len(_s2s_args) == 4 else None
612
640
  else:
613
641
  raise ValueError("Incorrect/incomplete specification for Excel cell data.")
614
642
 
615
643
  _write_args = (
616
- (*_cell_addr, repr(_cell_val))
617
- if np.ndim(_cell_val) or _cell_val in (np.inf, -np.inf, np.nan)
618
- else (*_cell_addr, _cell_val)
644
+ *_address,
645
+ (
646
+ repr(_value)
647
+ if np.ndim(_value) or _value in (np.inf, -np.inf, np.nan)
648
+ else _value
649
+ ),
619
650
  )
620
- _write_args += (CFmt.xl_fmt(_xl_book, _cell_fmt),) if _cell_fmt else ()
651
+ _write_args += (CFmt.xl_fmt(_xl_book, _format),) if _format else ()
621
652
 
622
- if _cell_val is None or _cell_val == "":
653
+ if _value is None or _value == "":
623
654
  _xl_sheet.write_blank(*_write_args)
624
655
  elif (
625
- isinstance(_cell_val, str)
626
- or np.ndim(_cell_val)
627
- or _cell_val in (np.inf, -np.inf, np.nan)
656
+ isinstance(_value, str)
657
+ or np.ndim(_value)
658
+ or _value in (np.inf, -np.inf, np.nan)
628
659
  ):
629
660
  _xl_sheet.write_string(*_write_args)
630
661
  else: