Skip to content

Commit a1e2b9a

Browse files
committed
TST: Add test for missing conversion
Add test to ensure conversion of large ints is correct
1 parent c30eb65 commit a1e2b9a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class PossiblePrecisionLoss(Warning):
469469

470470

471471
precision_loss_doc = """
472-
Column converted from %s to %s, and some data are outside of the lossless
472+
Column converted from {0} to {1}, and some data are outside of the lossless
473473
conversion range. This may result in a loss of precision in the saved data.
474474
"""
475475

pandas/tests/io/test_stata.py

+17
Original file line numberDiff line numberDiff line change
@@ -1980,3 +1980,20 @@ def test_iterator_value_labels():
19801980
for i in range(2):
19811981
tm.assert_index_equal(chunk.dtypes[i].categories, expected)
19821982
tm.assert_frame_equal(chunk, df.iloc[j * 100 : (j + 1) * 100])
1983+
1984+
1985+
def test_precision_loss():
1986+
df = pd.DataFrame(
1987+
[[sum(2 ** i for i in range(60)), sum(2 ** i for i in range(52))]],
1988+
columns=["big", "little"],
1989+
)
1990+
with tm.ensure_clean() as path:
1991+
with tm.assert_produces_warning(
1992+
PossiblePrecisionLoss, match="Column converted from int64 to float64"
1993+
):
1994+
df.to_stata(path, write_index=False)
1995+
reread = pd.read_stata(path)
1996+
expected_dt = pd.Series([np.float64, np.float64], index=["big", "little"])
1997+
tm.assert_series_equal(reread.dtypes, expected_dt)
1998+
assert reread.loc[0, "little"] == df.loc[0, "little"]
1999+
assert reread.loc[0, "big"] == float(df.loc[0, "big"])

0 commit comments

Comments
 (0)