Skip to content

Commit 398cf1b

Browse files
committed
fix e-notation bug
1 parent 63ae1d3 commit 398cf1b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/arraytex/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def to_tabular(
8282
8383
Raises:
8484
TooManyDimensionsError: when the supplied array has more than 2 dimensions
85-
DimensionMismatchError: when there are mismatched column identifiers and
86-
dimensions
85+
DimensionMismatchError: when there is a mismatch between column items and number
86+
of columns, or column index items and number of rows
8787
"""
8888
n_dims = len(arr.shape)
8989

src/arraytex/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def num_formatter(x: Union[np.int64, np.float64, np.float32]) -> str:
6161
)
6262

6363
if num_format and "e" in num_format:
64-
pattern = r"e(-?\d+)"
64+
pattern = r"e([\+-]?\d+)"
6565
replace = r"\\mathrm{e}{\g<1>}"
6666
if scientific_notation:
6767
replace = r" \\times 10^{\g<1>}"

tests/test_api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ def test_e_notation(self) -> None:
8787
== r"""\begin{bmatrix}
8888
1.00\mathrm{e}{-03} & 2.00\mathrm{e}{-03} & 3.00\mathrm{e}{-03} \\
8989
4.00\mathrm{e}{-03} & 5.00\mathrm{e}{-03} & 6.00\mathrm{e}{-03} \\
90+
\end{bmatrix}"""
91+
)
92+
93+
def test_e_notation_positive(self) -> None:
94+
"""Scientific E notation can be selected with positive powers."""
95+
mat = np.arange(6).reshape(2, 3)
96+
97+
out = to_matrix(mat, num_format=".2e")
98+
99+
assert (
100+
out
101+
== r"""\begin{bmatrix}
102+
0.00\mathrm{e}{+00} & 1.00\mathrm{e}{+00} & 2.00\mathrm{e}{+00} \\
103+
3.00\mathrm{e}{+00} & 4.00\mathrm{e}{+00} & 5.00\mathrm{e}{+00} \\
90104
\end{bmatrix}"""
91105
)
92106

0 commit comments

Comments
 (0)