Skip to content

Commit

Permalink
fixed nan for writing pandas in UDFs closes #446
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Apr 21, 2016
1 parent 4c44441 commit 6c3c443
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions xlwings/_xlwindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def prepare_xl_data_element(x):
return float(x)
elif x is None:
return ""
elif np and isinstance(x, float) and np.isnan(x):
return ""
else:
return x

Expand Down
4 changes: 1 addition & 3 deletions xlwings/conversion/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ class CleanDataForWriteStage(object):
def __call__(self, c):
c.value = [
[
None
if np and isinstance(x, float) and np.isnan(x)
else xlplatform.prepare_xl_data_element(x)
xlplatform.prepare_xl_data_element(x)
for x in y
]
for y in c.value
Expand Down
4 changes: 4 additions & 0 deletions xlwings/tests/udfs/udf_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def read_timeseries(x):
def write_timeseries():
return pd.Series([1.5, 2.5], name='ts', index=[datetime(2000, 12, 20), datetime(2000, 12, 21)])

@xw.func
def write_series_nan():
return pd.Series([1, np.nan, 3])

# Pandas DataFrame

if pd:
Expand Down
Binary file modified xlwings/tests/udfs/udf_tests.xlsm
Binary file not shown.

0 comments on commit 6c3c443

Please sign in to comment.