Skip to content

Commit

Permalink
Version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kz26 committed Jul 29, 2013
1 parent 2412a44 commit 559f2ba
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.3.0 - July 29, 2013
* Fixed bug in __coordinate_to_string function
* Compatibility fixes for Python 3 and numpy datatypes
* Updated test suite to work with Python 3

# 0.2.6 - July 10, 2013
* Better PyInstaller compatibility (sys.executable in addition to sys.\_MEIPASS

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Accelerated Excel XLSX writing library for Python 2/3

* Current version: 0.2.6
* Current version: 0.3.0
* Authors: [Kevin Wang](https://github.com/kevmo314) and [Kevin Zhang](https://github.com/whitehat2k9)
* License: Simplified BSD License
* [Source repository](https://github.com/whitehat2k9/PyExcelerate)
Expand Down
13 changes: 11 additions & 2 deletions pyexcelerate/DataTypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from datetime import datetime
from . import six
try:
import numpy as np
HAS_NUMPY = True
except:
HAS_NUMPY = False

class DataTypes(object):
BOOLEAN = 0
Expand All @@ -12,6 +17,8 @@ class DataTypes(object):
FORMULA = 7

_enumerations = ["b", "d", "e", "inlineStr", "n", "s", "str"]
_numberTypes = six.integer_types + (float, complex)

@staticmethod
def to_enumeration_value(index):
return DataTypes._enumerations[index]
Expand All @@ -25,15 +32,17 @@ def get_type(value):
else:
return DataTypes.INLINE_STRING
# not using in (int, float, long, complex) for speed
elif value.__class__ in six.integer_types + (float, complex):
elif value.__class__ in DataTypes._numberTypes:
return DataTypes.NUMBER
# fall back to the slower isinstance
elif isinstance(value, six.string_types):
if len(value) > 0 and value[0] == '=':
return DataTypes.FORMULA
else:
return DataTypes.INLINE_STRING
elif isinstance(value, six.integer_types + (float, complex)):
elif isinstance(value, DataTypes._numberTypes):
return DataTypes.NUMBER
elif HAS_NUMPY and isinstance(value, (np.floating, np.integer, np.complexfloating, np.unsignedinteger)):
return DataTypes.NUMBER
elif isinstance(value, datetime):
return DataTypes.DATE
Expand Down
3 changes: 1 addition & 2 deletions pyexcelerate/Range.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ def coordinate_to_string(coord):
s = ""
while y >= 0:
s = chr((y % 26) + Range.A) + s
y /= 26
y -= 1
y = int(y / 26) - 1
Range._cts_cache[y] = s
return Range._cts_cache[y] + str(coord[0])

Expand Down
36 changes: 18 additions & 18 deletions pyexcelerate/tests/test_DataTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
import numpy

def test__to_enumeration_value():
eq_(DataTypes.to_enumeration_value(DataTypes.BOOLEAN), "b")
eq_(DataTypes.to_enumeration_value(DataTypes.DATE), "d")
eq_(DataTypes.to_enumeration_value(DataTypes.ERROR), "e")
eq_(DataTypes.to_enumeration_value(DataTypes.INLINE_STRING), "inlineStr")
eq_(DataTypes.to_enumeration_value(DataTypes.NUMBER), "n")
eq_(DataTypes.to_enumeration_value(DataTypes.SHARED_STRING), "s")
eq_(DataTypes.to_enumeration_value(DataTypes.STRING), "str")
eq_(DataTypes.to_enumeration_value(DataTypes.BOOLEAN), "b")
eq_(DataTypes.to_enumeration_value(DataTypes.DATE), "d")
eq_(DataTypes.to_enumeration_value(DataTypes.ERROR), "e")
eq_(DataTypes.to_enumeration_value(DataTypes.INLINE_STRING), "inlineStr")
eq_(DataTypes.to_enumeration_value(DataTypes.NUMBER), "n")
eq_(DataTypes.to_enumeration_value(DataTypes.SHARED_STRING), "s")
eq_(DataTypes.to_enumeration_value(DataTypes.STRING), "str")

def test__get_type():
eq_(DataTypes.get_type(15), DataTypes.NUMBER)
eq_(DataTypes.get_type(15.0), DataTypes.NUMBER)
eq_(DataTypes.get_type("test"), DataTypes.INLINE_STRING)
eq_(DataTypes.get_type(datetime.now()), DataTypes.DATE)
eq_(DataTypes.get_type(15), DataTypes.NUMBER)
eq_(DataTypes.get_type(15.0), DataTypes.NUMBER)
eq_(DataTypes.get_type("test"), DataTypes.INLINE_STRING)
eq_(DataTypes.get_type(datetime.now()), DataTypes.DATE)
def test_numpy():
testData = numpy.ones((5, 5), dtype = int)
wb = Workbook()
ws = wb.new_sheet("Test 1", data=testData)
eq_(ws[1][1].value, 1)
eq_(DataTypes.get_type(ws[1][1].value), DataTypes.NUMBER)
wb.save("numpy-test.xlsx")
testData = numpy.ones((5, 5), dtype = int)
wb = Workbook()
ws = wb.new_sheet("Test 1", data=testData)
eq_(ws[1][1].value, 1)
eq_(DataTypes.get_type(ws[1][1].value), DataTypes.NUMBER)
wb.save("numpy-test.xlsx")

0 comments on commit 559f2ba

Please sign in to comment.