Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Here is a list of past and present much-appreciated contributors:
Andrii Soldatenko
Benjamin Wohlwend
Bruno Soares
Charles Tonneslan
Claude Paroz
Daniel Santos
Egor Osokin
Expand Down
2 changes: 1 addition & 1 deletion src/tablib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def add_formatter(self, col, handler):
else:
raise KeyError

if col is None or col <= self.width:
if col is None or col < self.width:
self._formatters.append((col, handler))
else:
raise InvalidDatasetIndex
Expand Down
7 changes: 6 additions & 1 deletion tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import tablib
from tablib.core import Row, detect_format
from tablib.exceptions import UnsupportedFormat
from tablib.exceptions import InvalidDatasetIndex, UnsupportedFormat
from tablib.formats import registry

try:
Expand Down Expand Up @@ -603,6 +603,11 @@ def _formatter(cell_value):
# Test once more as the result should be the same
self.assertEqual(self.founders.dict, expected)

def test_formatter_invalid_column_index(self):
"""Registering a formatter on an out-of-range index is rejected."""
with self.assertRaises(InvalidDatasetIndex):
self.founders.add_formatter(self.founders.width, str)

def test_formatters_all_cols(self):
"""
Passing None as first add_formatter param apply formatter to all columns.
Expand Down