Skip to content

Commit 4f2e7fe

Browse files
committed
handl 0 dimensions for tabular
1 parent 6bee90f commit 4f2e7fe

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/arraytex/api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ def to_tabular(
8282
DimensionMismatchError: when there are mismatched column identifiers and
8383
dimensions
8484
"""
85-
if len(arr.shape) == 1:
85+
n_dims = len(arr.shape)
86+
87+
if n_dims == 0:
88+
n_cols = 1
89+
elif n_dims == 1:
8690
n_cols = arr.shape[0]
87-
elif len(arr.shape) == 2:
91+
elif n_dims == 2:
8892
n_cols = arr.shape[1]
8993
else:
9094
raise TooManyDimensionsError

tests/test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,22 @@ def test_one_dimensional(self) -> None:
259259
\midrule
260260
1 & 2 & 3 \\
261261
\endrule
262+
\end{tabular}"""
263+
)
264+
265+
def test_0_d(self) -> None:
266+
"""0 dimensional scalars are handled properly."""
267+
mat = np.array(1)
268+
269+
out = to_tabular(mat)
270+
271+
assert (
272+
out
273+
== r"""\begin{tabular}{c}
274+
\toprule
275+
Col 1 \\
276+
\midrule
277+
1 \\
278+
\endrule
262279
\end{tabular}"""
263280
)

0 commit comments

Comments
 (0)