From a138afdcdf97565e481fd96f3099de3d2fc04237 Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Sun, 30 Jun 2024 22:27:46 -0700 Subject: [PATCH] Fix incorrect value display for auto string width (#37) --- matrepr/adapters/__init__.py | 7 +------ tests/test_numpy.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/matrepr/adapters/__init__.py b/matrepr/adapters/__init__.py index d3c5b83..60d52dc 100644 --- a/matrepr/adapters/__init__.py +++ b/matrepr/adapters/__init__.py @@ -397,12 +397,7 @@ def drop_column(self): drop = self.dot_col else: assert self.dot_col <= old_dot_col - if self.dot_col == 0: - drop = self.dot_col - elif self.dot_col < old_dot_col: - drop = self.dot_col - 1 - else: - drop = self.dot_col + drop = self.dot_col # adjust metadata self.display_shape[1] -= 1 diff --git a/tests/test_numpy.py b/tests/test_numpy.py index b2e1712..0e00e7e 100644 --- a/tests/test_numpy.py +++ b/tests/test_numpy.py @@ -67,6 +67,22 @@ def test_large_size(self): res = to_latex(mat, max_rows=None, max_cols=None) self.assertNotIn("dots", res) + def test_gh_35(self): + mat = np.arange(5000).reshape(2, 2500) + res = to_str(mat, width_str=50) + self.assertNotIn("6 ", res) + + def test_auto_width_str_vals(self): + mat = np.arange(5000) + # Try a range of string widths. + for width_str in range(1, 200): + res = to_str(mat, width_str=width_str) + # The header has the expected matrix value, so compare the two. + lines = res.split("\n") + headers = lines[1].split() + vals = lines[2].replace("...", " ").replace("[", "").replace("]", "").split() + self.assertEqual(headers, vals) + if __name__ == '__main__': unittest.main()