8000 :bug: fix the conversion issue for long type on python 2. fix #67 · pyexcel/pyexcel-io@4034787 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4034787

Browse files
committed
🐛 fix the conversion issue for long type on python 2. fix #67
1 parent 29a7ffc commit 4034787

File tree

2 files changed

+21
-3
lines changed
  • pyexcel_io
  • tests

2 files changed

+21
-3
lines changed

pyexcel_io/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def boolean_value(value):
180180

181181
if PY2:
182182
ODS_WRITE_FORMAT_COVERSION[unicode] = "string" # noqa: F821
183-
ODS_WRITE_FORMAT_COVERSION[long] = "throw_exception" # noqa: F821
183+
ODS_WRITE_FORMAT_COVERSION[long] = "long" # noqa: F821
184184

185185

186186
VALUE_CONVERTERS = {
@@ -198,7 +198,7 @@ def throw_exception(value):
198198

199199

200200
def ods_float_value(value):
201-
if int(value) > int(constants.MAX_INTEGER):
201+
if value > constants.MAX_INTEGER:
202202
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
203203
return value
204204

@@ -234,7 +234,7 @@ def ods_timedelta_value(cell):
234234
"boolean": ods_bool_value,
235235
"timedelta": ods_timedelta_value,
236236
"float": ods_float_value,
237-
"throw_exception": throw_exception
237+
"long": ods_float_value
238238
}
239239

240240

tests/test_service.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from nose.tools import eq_, raises
23
from pyexcel_io.service import date_value, time_value
34
from pyexcel_io.service import detect_int_value
@@ -9,6 +10,8 @@
910
from pyexcel_io.exceptions import IntegerAccuracyLossError
1011
from nose import SkipTest
1112

13+
PY2 = sys.version[0] == 2
14+
1215

1316
def test_date_util_parse():
1417
value = "2015-08-17T19:20:00"
@@ -110,6 +113,21 @@ def test_big_int_value():
110113
ods_float_value(1000000000000000)
111114

112115

116+
def test_max_value_on_python_2():
117+
if PY2:
118+
ods_float_value(long(999999999999999))
119+
else:
120+
raise SkipTest("No long in python 3")
121+
122+
123+
@raises(IntegerAccuracyLossError)
124+
def test_really_long_value_on_python2():
125+
if PY2:
126+
ods_float_value(long(999999999999999+1))
127+
else:
128+
raise SkipTest("No long in python 3")
129+
130+
113131
@raises(IntegerAccuracyLossError)
114132
def test_throw_exception():
115133
throw_exception(1000000000000000)

0 commit comments

Comments
 (0)
0