Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash in DesignMatrix.__repr__ when shape[0] == 0 #83

Merged
merged 1 commit into from
Apr 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions patsy/design_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,13 @@ def _repr_pretty_(self, p, cycle):
formatted_cols = [_format_float_column(PRECISION,
printable_part[:, i])
for i in range(self.shape[1])]
column_num_widths = [max([len(s) for s in col])
for col in formatted_cols]
def max_width(col):
assert col.ndim == 1
if not col.shape[0]:
return 0
else:
return max([len(s) for s in col])
column_num_widths = [max_width(col) for col in formatted_cols]
column_widths = [max(name_width, num_width)
for (name_width, num_width)
in zip(column_name_widths, column_num_widths)]
Expand Down Expand Up @@ -1188,3 +1193,7 @@ def test_design_matrix():
repr(DesignMatrix(np.arange(100).reshape((1, 100))))
repr(DesignMatrix([np.nan, np.inf]))
repr(DesignMatrix([np.nan, 0, 1e20, 20.5]))
# handling of zero-size matrices
repr(DesignMatrix(np.zeros((1, 0))))
repr(DesignMatrix(np.zeros((0, 1))))
repr(DesignMatrix(np.zeros((0, 0))))