Skip to content

Commit 0d1151e

Browse files
authored
Merge pull request #50 from pyexcel/dev
release 0.5.8
2 parents d2e1e8a + 4f06d5a commit 0d1151e

15 files changed

+271
-41
lines changed

.moban.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ configuration:
44
- "commons/templates"
55
- "setupmobans/templates"
66
- ".moban.d"
7-
configuration: pyexcel_io.yaml
7+
configuration: pyexcel-io.yml
88
targets:
99
- "docs/source/conf.py": "docs/source/conf.py"
1010
- setup.py: setup.py

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ notifications:
44
email: false
55
python:
66
- pypy-5.3.1
7+
- 3.7-dev
78
- 3.6
89
- 3.5
910
- 3.4

CHANGELOG.rst

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Change log
22
================================================================================
33

4+
0.5.8 - unreleased
5+
--------------------------------------------------------------------------------
6+
7+
fixed
8+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
10+
#. `#49 <https://github.com/pyexcel/pyexcel-io/issues/49>`_, support additional
11+
options when detecting float values in csv format. default_float_nan,
12+
ignore_nan_text
13+
414
0.5.7 - 02.05.2018
515
--------------------------------------------------------------------------------
616

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ that the following conditions are met:
1313
and/or other materials provided with the distribution.
1414

1515
* Neither the name of 'pyexcel-io' nor the names of the contributors
16-
may not be used to endorse or promote products derived from this software
16+
may be used to endorse or promote products derived from this software
1717
without specific prior written permission.
1818

1919
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
@@ -27,4 +27,4 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2727
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2828
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2929
SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30-
DAMAGE.
30+
DAMAGE.

changelog.yml

+6
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: fixed
6+
details:
7+
- '`#49`, support additional options when detecting float values in csv format. default_float_nan, ignore_nan_text'
8+
date: unreleased
9+
version: 0.5.8
410
- changes:
511
- action: fixed
612
details:

docs/source/conf.py

+173-18
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,205 @@
44
'format and to/from databases' +
55
''
66
)
7+
# -*- coding: utf-8 -*-
8+
#
9+
# Configuration file for the Sphinx documentation builder.
10+
#
11+
# This file does only contain a selection of the most common options. For a
12+
# full list see the documentation:
13+
# http://www.sphinx-doc.org/en/master/config
14+
15+
# -- Path setup --------------------------------------------------------------
16+
17+
# If extensions (or modules to document with autodoc) are in another directory,
18+
# add these directories to sys.path here. If the directory is relative to the
19+
# documentation root, use os.path.abspath to make it absolute, like shown here.
20+
#
21+
# import os
22+
# import sys
23+
# sys.path.insert(0, os.path.abspath('.'))
24+
25+
# -- Project information -----------------------------------------------------
26+
27+
project = u'pyexcel-io'
28+
copyright = u'2015-2018 Onni Software Ltd.'
29+
author = u'C.W.'
30+
31+
# The short X.Y version
32+
version = u'0.5.8'
33+
# The full version, including alpha/beta/rc tags
34+
release = u'0.5.8'
35+
36+
37+
# -- General configuration ---------------------------------------------------
38+
39+
# If your documentation needs a minimal Sphinx version, state it here.
40+
#
41+
# needs_sphinx = '1.0'
42+
43+
# Add any Sphinx extension module names here, as strings. They can be
44+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
45+
# ones.
746
extensions = [
847
'sphinx.ext.autodoc',
948
'sphinx.ext.doctest',
1049
'sphinx.ext.intersphinx',
1150
'sphinx.ext.viewcode',
12-
'sphinx.ext.autosummary'
1351
]
14-
intersphinx_mapping = {
15-
'pyexcel': ('http://pyexcel.readthedocs.io/en/latest/', None),
16-
}
52+
53+
# Add any paths that contain templates here, relative to this directory.
1754
templates_path = ['_templates']
55+
56+
# The suffix(es) of source filenames.
57+
# You can specify multiple suffix as a list of string:
58+
#
59+
# source_suffix = ['.rst', '.md']
1860
source_suffix = '.rst'
61+
62+
# The master toctree document.
1963
master_doc = 'index'
2064

21-
project = u'pyexcel-io'
22-
copyright = u'2015-2018 Onni Software Ltd.'
23-
version = '0.5.7'
24-
release = '0.5.7'
65+
# The language for content autogenerated by Sphinx. Refer to documentation
66+
# for a list of supported languages.
67+
#
68+
# This is also used if you do content translation via gettext catalogs.
69+
# Usually you set "language" from the command line for these cases.
70+
language = 'en'
71+
72+
# List of patterns, relative to source directory, that match files and
73+
# directories to ignore when looking for source files.
74+
# This pattern also affects html_static_path and html_extra_path.
2575
exclude_patterns = []
76+
77+
# The name of the Pygments (syntax highlighting) style to use.
2678
pygments_style = 'sphinx'
27-
html_theme = 'default'
2879

2980

30-
def setup(app):
31-
app.add_stylesheet('theme_overrides.css')
81+
# -- Options for HTML output -------------------------------------------------
82+
83+
# The theme to use for HTML and HTML Help pages. See the documentation for
84+
# a list of builtin themes.
85+
#
86+
html_theme = 'alabaster'
3287

88+
# Theme options are theme-specific and customize the look and feel of a theme
89+
# further. For a list of options available for each theme, see the
90+
# documentation.
91+
#
92+
# html_theme_options = {}
3393

94+
# Add any paths that contain custom static files (such as style sheets) here,
95+
# relative to this directory. They are copied after the builtin static files,
96+
# so a file named "default.css" will overwrite the builtin "default.css".
3497
html_static_path = ['_static']
98+
99+
# Custom sidebar templates, must be a dictionary that maps document names
100+
# to template names.
101+
#
102+
# The default sidebars (for documents that don't match any pattern) are
103+
# defined by theme itself. Builtin themes are using these templates by
104+
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
105+
# 'searchbox.html']``.
106+
#
107+
# html_sidebars = {}
108+
109+
110+
# -- Options for HTMLHelp output ---------------------------------------------
111+
112+
# Output file base name for HTML help builder.
35113
htmlhelp_basename = 'pyexcel-iodoc'
36-
latex_elements = {}
114+
115+
116+
# -- Options for LaTeX output ------------------------------------------------
117+
118+
latex_elements = {
119+
# The paper size ('letterpaper' or 'a4paper').
120+
#
121+
# 'papersize': 'letterpaper',
122+
123+
# The font size ('10pt', '11pt' or '12pt').
124+
#
125+
# 'pointsize': '10pt',
126+
127+
# Additional stuff for the LaTeX preamble.
128+
#
129+
# 'preamble': '',
130+
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
134+
}
135+
136+
# Grouping the document tree into LaTeX files. List of tuples
137+
# (source start file, target name, title,
138+
# author, documentclass [howto, manual, or own class]).
37139
latex_documents = [
38-
('index', 'pyexcel-io.tex',
39-
'pyexcel-io Documentation',
40-
'Onni Software Ltd.', 'manual'),
140+
(master_doc, 'pyexcel-io.tex', u'pyexcel-io Documentation',
141+
u'Onni Software Ltd.', 'manual'),
41142
]
143+
144+
145+
# -- Options for manual page output ------------------------------------------
146+
147+
# One entry per manual page. List of tuples
148+
# (source start file, name, description, authors, manual section).
42149
man_pages = [
43-
('index', 'pyexcel-io',
44-
'pyexcel-io Documentation',
45-
[u'Onni Software Ltd.'], 1)
150+
(master_doc, 'pyexcel-io', u'pyexcel-io Documentation',
151+
[author], 1)
46152
]
153+
154+
155+
# -- Options for Texinfo output ----------------------------------------------
156+
157+
# Grouping the document tree into Texinfo files. List of tuples
158+
# (source start file, target name, title, author,
159+
# dir menu entry, description, category)
160+
texinfo_documents = [
161+
(master_doc, 'pyexcel-io', u'pyexcel-io Documentation',
162+
author, 'pyexcel-io', 'One line description of project.',
163+
'Miscellaneous'),
164+
]
165+
166+
167+
# -- Options for Epub output -------------------------------------------------
168+
169+
# Bibliographic Dublin Core info.
170+
epub_title = project
171+
172+
# The unique identifier of the text. This can be a ISBN number
173+
# or the project homepage.
174+
#
175+
# epub_identifier = ''
176+
177+
# A unique identification for the text.
178+
#
179+
# epub_uid = ''
180+
181+
# A list of files that should not be packed into the epub file.
182+
epub_exclude_files = ['search.html']
183+
184+
# -- Extension configuration -------------------------------------------------
185+
# -- Options for intersphinx extension ---------------------------------------
186+
187+
# Example configuration for intersphinx: refer to the Python standard library.
188+
intersphinx_mapping = {'https://docs.python.org/': None}
189+
# TODO: html_theme not configurable upstream
190+
html_theme = 'default'
191+
192+
193+
def setup(app):
194+
app.add_stylesheet('theme_overrides.css')
195+
196+
197+
198+
# TODO: DESCRIPTION not configurable upstream
47199
texinfo_documents = [
48200
('index', 'pyexcel-io',
49201
'pyexcel-io Documentation',
50202
'Onni Software Ltd.', 'pyexcel-io',
51203
DESCRIPTION,
52204
'Miscellaneous'),
53205
]
206+
intersphinx_mapping.update({
207+
'pyexcel': ('http://pyexcel.readthedocs.io/en/latest/', None),
208+
})

pyexcel_io.yaml renamed to pyexcel-io.yml

+3-3
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.7
5-
current_version: 0.5.7
6-
release: 0.5.7
4+
version: 0.5.8
5+
current_version: 0.5.8
6+
release: 0.5.8
77
dependencies:
88
- ordereddict;python_version<"2.7"
99
- lml==0.0.1

pyexcel_io/io.py

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def iget_data(afile, file_type=None, **keywords):
3232
:param auto_detect_int: defaults to True
3333
:param auto_detect_datetime: defaults to True
3434
:param ignore_infinity: defaults to True
35+
:param ignore_nan_text: various forms of 'NaN', 'nan' are ignored
36+
:param default_float_nan: choose one form of 'NaN', 'nan'
37+
:param pep_0515_off: turn off pep 0515. default to True.
3538
:param keywords: any other library specific parameters
3639
:returns: an ordered dictionary
3740
"""

pyexcel_io/readers/csvr.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def __init__(
131131
auto_detect_int=True,
132132
auto_detect_datetime=True,
133133
pep_0515_off=True,
134+
ignore_nan_text=False,
135+
default_float_nan=None,
134136
**keywords
135137
):
136138
SheetReader.__init__(self, sheet, **keywords)
@@ -141,6 +143,8 @@ def __init__(
141143
self.__auto_detect_datetime = auto_detect_datetime
142144
self.__file_handle = None
143145
self.__pep_0515_off = pep_0515_off
146+
self.__ignore_nan_text = ignore_nan_text
147+
self.__default_float_nan = default_float_nan
144148

145149
def get_file_handle(self):
146150
""" return me unicde reader for csv """
@@ -164,7 +168,9 @@ def __convert_cell(self, csv_cell_text):
164168
ret = service.detect_int_value(csv_cell_text, self.__pep_0515_off)
165169
if ret is None and self.__auto_detect_float:
166170
ret = service.detect_float_value(
167-
csv_cell_text, self.__pep_0515_off
171+
csv_cell_text, self.__pep_0515_off,
172+
ignore_nan_text=self.__ignore_nan_text,
173+
default_float_nan=self.__default_float_nan
168174
)
169175
shall_we_ignore_the_conversion = (
170176
(ret in [float("inf"), float("-inf")])

pyexcel_io/service.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def detect_date_value(cell_text):
3939
return ret
4040

4141

42-
def detect_float_value(cell_text, pep_0515_off=True):
42+
def detect_float_value(
43+
cell_text, pep_0515_off=True,
44+
ignore_nan_text=False,
45+
default_float_nan=None):
4346
should_we_skip_it = (
4447
cell_text.startswith("0") and cell_text.startswith("0.") is False
4548
)
@@ -54,7 +57,19 @@ def detect_float_value(cell_text, pep_0515_off=True):
5457
return None
5558

5659
try:
57-
return float(cell_text)
60+
if ignore_nan_text:
61+
if cell_text.lower() == "nan":
62+
return None
63+
else:
64+
return float(cell_text)
65+
else:
66+
if cell_text.lower() == "nan":
67+
if cell_text == default_float_nan:
68+
return float("NaN")
69+
else:
70+
return None
71+
else:
72+
return float(cell_text)
5873
except ValueError:
5974
return None
6075

0 commit comments

Comments
 (0)