Skip to content

Commit

Permalink
Merge pull request #231 from best-practice-and-impact/227-write_workb…
Browse files Browse the repository at this point in the history
…ook-errors-with-all-integer-table

Casts columns to string before checking for special characters
  • Loading branch information
danmilne1 authored Jun 28, 2024
2 parents f3c87d9 + 476faaa commit 8a368ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']


steps:
- uses: actions/checkout@v2
Expand All @@ -71,7 +72,8 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']


steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion gptables/core/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def _write_table_elements(self, pos, gptable, auto_width):
warnings.warn(msg)

# Raise error if any table element is only special characters
if gptable.table.stack().str.contains('^[^a-zA-Z0-9]*$').any():
if gptable.table.astype("string").stack().str.contains('^[^a-zA-Z0-9]*$').any():
msg = (f"""
Cell found in {gptable.table_name} containing only special characters,
replace with alphanumeric characters before inputting to GPTable.
Expand Down
8 changes: 8 additions & 0 deletions gptables/test/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ def test__write_empty_table(self, testbook, create_gptable_with_kwargs):
with pytest.raises(ValueError):
testbook.ws._write_table_elements([0,0], gptable, auto_width=True)

def test__write_integer_table(self, testbook, create_gptable_with_kwargs):
gptable = create_gptable_with_kwargs({
"table": pd.DataFrame({"a": [0], "b": [1]})
})

#Testing that this function executes with no errors
testbook.ws._write_table_elements([0,0], gptable, auto_width=True)


@pytest.mark.parametrize("cell_value1,cell_value2,expectation", [
(None, "valid text", pytest.warns(UserWarning)),
Expand Down

0 comments on commit 8a368ea

Please sign in to comment.