Skip to content

Commit 03b1cb4

Browse files
committed
TST: Add tests for all None
Test exception is hit when all values in an object column are None Extend the test for strl conversion to ensure this case passes (as expected)
1 parent 3eb95fd commit 03b1cb4

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pandas/tests/io/test_stata.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,11 +1514,34 @@ def test_mixed_string_strl(self):
15141514
{'mixed': None,
15151515
'number': 1}
15161516
]
1517-
15181517
output = pd.DataFrame(output)
1518+
output.number = output.number.astype('int32')
1519+
15191520
with tm.ensure_clean() as path:
15201521
output.to_stata(path, write_index=False, version=117)
15211522
reread = read_stata(path)
15221523
expected = output.fillna('')
1523-
expected.number = expected.number.astype('int32')
15241524
tm.assert_frame_equal(reread, expected)
1525+
1526+
# Check strl supports all None (null)
1527+
output.loc[:, 'mixed'] = None
1528+
output.to_stata(path, write_index=False, convert_strl=['mixed'],
1529+
version=117)
1530+
reread = read_stata(path)
1531+
expected = output.fillna('')
1532+
tm.assert_frame_equal(reread, expected)
1533+
1534+
@pytest.mark.parametrize('version', [114, 117])
1535+
def test_all_none_exception(self, version):
1536+
output = [
1537+
{'none': 'none',
1538+
'number': 0},
1539+
{'none': None,
1540+
'number': 1}
1541+
]
1542+
output = pd.DataFrame(output)
1543+
output.loc[:, 'none'] = None
1544+
with tm.ensure_clean() as path:
1545+
with pytest.raises(ValueError) as excinfo:
1546+
output.to_stata(path, version=version)
1547+
assert 'Only string-like' in excinfo.value.args[0]

0 commit comments

Comments
 (0)