|
11 | 11 |
|
12 | 12 | import nose
|
13 | 13 | import numpy as np
|
14 |
| -from pandas.tslib import NaT |
15 |
| - |
16 | 14 | import pandas as pd
|
17 | 15 | import pandas.util.testing as tm
|
18 | 16 | from pandas import compat
|
|
21 | 19 | from pandas.io.parsers import read_csv
|
22 | 20 | from pandas.io.stata import (read_stata, StataReader, InvalidColumnName,
|
23 | 21 | PossiblePrecisionLoss, StataMissingValue)
|
| 22 | +from pandas.tslib import NaT |
24 | 23 | from pandas.types.common import is_categorical_dtype
|
25 | 24 |
|
26 | 25 |
|
@@ -1234,6 +1233,52 @@ def test_stata_111(self):
|
1234 | 1233 | original = original[['y', 'x', 'w', 'z']]
|
1235 | 1234 | tm.assert_frame_equal(original, df)
|
1236 | 1235 |
|
| 1236 | + def test_out_of_range_double(self): |
| 1237 | + # GH 14618 |
| 1238 | + df = DataFrame({'ColumnOk': [0.0, |
| 1239 | + np.finfo(np.double).eps, |
| 1240 | + 4.49423283715579e+307], |
| 1241 | + 'ColumnTooBig': [0.0, |
| 1242 | + np.finfo(np.double).eps, |
| 1243 | + np.finfo(np.double).max]}) |
| 1244 | + with tm.assertRaises(ValueError) as cm: |
| 1245 | + with tm.ensure_clean() as path: |
| 1246 | + df.to_stata(path) |
| 1247 | + tm.assertTrue('ColumnTooBig' in cm.exception) |
| 1248 | + |
| 1249 | + df.loc[2, 'ColumnTooBig'] = np.inf |
| 1250 | + with tm.assertRaises(ValueError) as cm: |
| 1251 | + with tm.ensure_clean() as path: |
| 1252 | + df.to_stata(path) |
| 1253 | + tm.assertTrue('ColumnTooBig' in cm.exception) |
| 1254 | + tm.assertTrue('infinity' in cm.exception) |
| 1255 | + |
| 1256 | + def test_out_of_range_float(self): |
| 1257 | + original = DataFrame({'ColumnOk': [0.0, |
| 1258 | + np.finfo(np.float32).eps, |
| 1259 | + np.finfo(np.float32).max / 10.0], |
| 1260 | + 'ColumnTooBig': [0.0, |
| 1261 | + np.finfo(np.float32).eps, |
| 1262 | + np.finfo(np.float32).max]}) |
| 1263 | + original.index.name = 'index' |
| 1264 | + for col in original: |
| 1265 | + original[col] = original[col].astype(np.float32) |
| 1266 | + |
| 1267 | + with tm.ensure_clean() as path: |
| 1268 | + original.to_stata(path) |
| 1269 | + reread = read_stata(path) |
| 1270 | + original['ColumnTooBig'] = original['ColumnTooBig'].astype( |
| 1271 | + np.float64) |
| 1272 | + tm.assert_frame_equal(original, |
| 1273 | + reread.set_index('index')) |
| 1274 | + |
| 1275 | + original.loc[2, 'ColumnTooBig'] = np.inf |
| 1276 | + with tm.assertRaises(ValueError) as cm: |
| 1277 | + with tm.ensure_clean() as path: |
| 1278 | + original.to_stata(path) |
| 1279 | + tm.assertTrue('ColumnTooBig' in cm.exception) |
| 1280 | + tm.assertTrue('infinity' in cm.exception) |
| 1281 | + |
1237 | 1282 |
|
1238 | 1283 | if __name__ == '__main__':
|
1239 | 1284 | nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
|
|
0 commit comments