Skip to content

Commit

Permalink
Fix incorrect value display for auto string width
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Jul 1, 2024
1 parent f70b01c commit 9f896f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 1 addition & 6 deletions matrepr/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 9f896f0

Please sign in to comment.