Skip to content

Commit eb3b1c3

Browse files
authored
Merge pull request #58 from pyexcel/v0.5.10
V0.5.10
2 parents c119c1a + 4637498 commit eb3b1c3

File tree

10 files changed

+107
-21
lines changed

10 files changed

+107
-21
lines changed

CHANGELOG.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
Change log
22
================================================================================
33

4+
0.5.10 - 27.11.2018
5+
--------------------------------------------------------------------------------
6+
7+
added
8+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
10+
#. `#57 <https://github.com/pyexcel/pyexcel-io/issues/57>`_, long type will not
11+
be written in ods. please use string type. And if the integer is equal or
12+
greater than 10 to the power of 16, it will not be written either in ods. In
13+
both situation, IntegerPrecisionLossError will be raised. And this version
14+
enables pyexcel-ods and pyexcel-ods3 to do so.
15+
416
0.5.9.1 - 30.08.2018
517
--------------------------------------------------------------------------------
618

changelog.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: pyexcel-io
22
organisation: pyexcel
33
releases:
4+
- changes:
5+
- action: added
6+
details:
7+
- '`#57`, long type will not be written in ods. please use string type. And if the integer is equal or greater than 10 to the power of 16, it will not be written either in ods. In both situation, IntegerPrecisionLossError will be raised. And this version enables pyexcel-ods and pyexcel-ods3 to do so.'
8+
date: 27.11.2018
9+
version: 0.5.10
410
- changes:
511
- action: updated
612
details:

docs/source/conf.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
author = u'C.W.'
3030

3131
# The short X.Y version
32-
version = u'0.5.9.1'
32+
version = u'0.5.10'
3333
# The full version, including alpha/beta/rc tags
34-
release = u'0.5.9.1'
34+
release = u'0.5.10'
3535

3636

3737
# -- General configuration ---------------------------------------------------
@@ -43,12 +43,7 @@
4343
# Add any Sphinx extension module names here, as strings. They can be
4444
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4545
# ones.
46-
extensions = [
47-
'sphinx.ext.autodoc',
48-
'sphinx.ext.doctest',
49-
'sphinx.ext.intersphinx',
50-
'sphinx.ext.viewcode',
51-
]
46+
extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode',]
5247

5348
# Add any paths that contain templates here, relative to this directory.
5449
templates_path = ['_templates']
@@ -75,7 +70,7 @@
7570
exclude_patterns = []
7671

7772
# The name of the Pygments (syntax highlighting) style to use.
78-
pygments_style = 'sphinx'
73+
pygments_style = None
7974

8075

8176
# -- Options for HTML output -------------------------------------------------

pyexcel-io.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
overrides: "pyexcel.yaml"
22
name: "pyexcel-io"
33
nick_name: io
4-
version: 0.5.9.1
5-
current_version: 0.5.9.1
6-
release: 0.5.9.1
4+
version: 0.5.10
5+
current_version: 0.5.10
6+
release: 0.5.10
77
dependencies:
88
- ordereddict;python_version<"2.7"
99
- lml>=0.0.2

pyexcel_io/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@
5959
SEPARATOR_MATCHER = "---%s:(.*)---" % DEFAULT_NAME
6060
DEFAULT_CSV_STREAM_FILE_FORMATTER = "---%s:" % DEFAULT_NAME + "%s---%s"
6161
DEFAULT_CSV_NEWLINE = "\r\n"
62+
63+
MAX_INTEGER = 999999999999999

pyexcel_io/exceptions.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,32 @@ class UpgradePlugin(Exception):
2525
"""raised when a known plugin is not compatible"""
2626

2727
pass
28+
29+
30+
class IntegerAccuracyLossError(Exception):
31+
"""
32+
When an interger is greater than 999999999999999, ods loses its accuracy.
33+
34+
from pyexcel import Sheet, get_sheet
35+
s = Sheet()
36+
s[0,0] = 999999999999999 # 15 '9's
37+
print(s)
38+
s.save_as('abc.ods')
39+
b=get_sheet(file_name='abc.ods')
40+
b[0,0] == s[0,0]
41+
42+
s = Sheet()
43+
s[0,0] = 9999999999999999 # 16 '9's
44+
print(s)
45+
s.save_as('abc.ods')
46+
b=get_sheet(file_name='abc.ods')
47+
b[0,0] != s[0,0]
48+
"""
49+
def __init__(self, message):
50+
custom_message = (
51+
message + '\n' +
52+
"In order to keep its accuracy, please save as string. Then " +
53+
"convert to int, long or float after the value will be read back"
54+
)
55+
56+
super(IntegerAccuracyLossError, self).__init__(custom_message)

pyexcel_io/readers/csvr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __next__(self):
8484
if bom_header == BOM_BIG_ENDIAN:
8585
self.__endian = BIG_ENDIAN
8686
elif self.__endian == LITTLE_ENDIAN:
87-
line = line[self.__zeros_left_in_2_row :] # flake8: noqa
87+
line = line[self.__zeros_left_in_2_row :] # noqa: E203
8888
if self.__endian == LITTLE_ENDIAN:
8989
line = line.rstrip()
9090
line = line.decode(self.__encoding)

pyexcel_io/service.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import datetime
1313

1414
from pyexcel_io._compact import PY2
15+
from pyexcel_io import constants
16+
from pyexcel_io import exceptions
1517

1618

1719
def has_no_digits_in_float(value):
@@ -127,7 +129,7 @@ def time_value(value):
127129
"""convert to time value accroding the specification"""
128130
import re
129131

130-
results = re.match("PT(\d+)H(\d+)M(\d+)S", value)
132+
results = re.match(r"PT(\d+)H(\d+)M(\d+)S", value)
131133
if results and len(results.groups()) == 3:
132134
hour = int(results.group(1))
133135
minute = int(results.group(2))
@@ -177,7 +179,9 @@ def boolean_value(value):
177179
}
178180

179181
if PY2:
180-
ODS_WRITE_FORMAT_COVERSION[unicode] = "string"
182+
ODS_WRITE_FORMAT_COVERSION[unicode] = "string" # noqa: F821
183+
ODS_WRITE_FORMAT_COVERSION[long] = "throw_exception" # noqa: F821
184+
181185

182186
VALUE_CONVERTERS = {
183187
"float": float_value,
@@ -189,6 +193,16 @@ def boolean_value(value):
189193
}
190194

191195

196+
def throw_exception(value):
197+
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
198+
199+
200+
def ods_float_value(value):
201+
if value > constants.MAX_INTEGER:
202+
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
203+
return value
204+
205+
192206
def ods_date_value(value):
193207
return value.strftime("%Y-%m-%d")
194208

@@ -219,6 +233,8 @@ def ods_timedelta_value(cell):
219233
"time": ods_time_value,
220234
"boolean": ods_bool_value,
221235
"timedelta": ods_timedelta_value,
236+
"float": ods_float_value,
237+
"throw_exception": throw_exception
222238
}
223239

224240

setup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,33 @@
55
import sys
66
import codecs
77
from shutil import rmtree
8-
from setuptools import setup, find_packages, Command
8+
9+
from setuptools import Command, setup, find_packages
10+
911
PY2 = sys.version_info[0] == 2
1012
PY26 = PY2 and sys.version_info[1] < 7
1113

1214
NAME = 'pyexcel-io'
1315
AUTHOR = 'C.W.'
14-
VERSION = '0.5.9.1'
16+
VERSION = '0.5.10'
1517
EMAIL = 'wangc_2011@hotmail.com'
1618
LICENSE = 'New BSD'
1719
DESCRIPTION = (
1820
'A python library to read and write structured data in csv, zipped csv' +
1921
'format and to/from databases'
2022
)
2123
URL = 'https://github.com/pyexcel/pyexcel-io'
22-
DOWNLOAD_URL = '%s/archive/0.5.9.1.tar.gz' % URL
24+
DOWNLOAD_URL = '%s/archive/0.5.10.tar.gz' % URL
2325
FILES = ['README.rst', 'CHANGELOG.rst']
2426
KEYWORDS = [
27+
'python',
2528
'API',
2629
'tsv',
2730
'tsvz',
2831
'csv',
2932
'csvz',
3033
'django',
3134
'sqlalchemy',
32-
'python',
3335
]
3436

3537
CLASSIFIERS = [
@@ -63,8 +65,8 @@
6365
# You do not need to read beyond this line
6466
PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format(
6567
sys.executable)
66-
GS_COMMAND = ('gs pyexcel-io v0.5.9.1 ' +
67-
"Find 0.5.9.1 in changelog for more details")
68+
GS_COMMAND = ('gs pyexcel-io v0.5.10 ' +
69+
"Find 0.5.10 in changelog for more details")
6870
NO_GS_MESSAGE = ('Automatic github release is disabled. ' +
6971
'Please install gease to enable it.')
7072
UPLOAD_FAILED_MSG = (

tests/test_service.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
from pyexcel_io.service import date_value, time_value
33
from pyexcel_io.service import detect_int_value
44
from pyexcel_io.service import detect_float_value
5+
from pyexcel_io.service import ODS_WRITE_FORMAT_COVERSION
6+
from pyexcel_io.service import ods_float_value
7+
from pyexcel_io.service import throw_exception
8+
from pyexcel_io._compact import PY2
9+
from pyexcel_io.exceptions import IntegerAccuracyLossError
10+
from nose import SkipTest
511

612

713
def test_date_util_parse():
@@ -89,3 +95,21 @@ def test_detect_float_value_on_custom_nan_text():
8995
def test_detect_float_value_on_custom_nan_text2():
9096
result = detect_float_value("nan", default_float_nan="nan")
9197
eq_(str(result), "nan")
98+
99+
100+
def test_ods_write_format_conversion():
101+
if PY2:
102+
expected = ODS_WRITE_FORMAT_COVERSION[long] # noqa: F821
103+
eq_('throw_exception', expected)
104+
else:
105+
raise SkipTest()
106+
107+
108+
@raises(IntegerAccuracyLossError)
109+
def test_big_int_value():
110+
ods_float_value(1000000000000000)
111+
112+
113+
@raises(IntegerAccuracyLossError)
114+
def test_throw_exception():
115+
throw_exception(1000000000000000)

0 commit comments

Comments
 (0)