Skip to content

Conversation

@ditenberg
Copy link

Updated _Openpyxl22Writer.write_cells() to use new coordinate call method wks['coordinate']
instead of wks.cell() in accordance with https://openpyxl.readthedocs.io/en/default/tutorial.html#accessing-one-cell
in the newest release of Openpyxl (2.4.0 and later).

I did not know how to write a true test for this fix since it involves Excel file I/O and pandas does not currently supporting reading in .xlsx as far as I know. The best I could do is use it with openpyxl 2.4.0 install on my machine and passing a small dataframe into an .xlsx. Please let me know if you have any suggestions on how to better test this.

Updated _Openpyxl22Writer.write_cells() to use new coordinate call method wks['coordinate']
instead of wks.cell() in accordance with https://openpyxl.readthedocs.io/en/default/tutorial.html#accessing-one-cell
in the newest release of Openpyxl (2.4.0 and later).
@ditenberg
Copy link
Author

@jorisvandenbossche if you could point me to where you think the UserWarning might be stemming from in pandas codebase then I'd be more than happy to take a look at it. I just went the most obvious edit that I could find and only that used this wks.cell(coordinate) method call. If you know of any other sources for the issue please let me know.

@TomAugspurger
Copy link
Contributor

@ditenberg for finding the UserWarning, you could try sticking

import warnings
warnings.simplefilter('error', UserWarning)

at the top of the excel file tests. That would turn any UserWarnings into exceptions. Glancing through the test file, it looks like we use .cell in a few places:

xcell_b1 = wks.cell('B1')

@TomAugspurger TomAugspurger added this to the 0.20.0 milestone Oct 30, 2016
@TomAugspurger TomAugspurger added IO Excel read_excel, to_excel Compat pandas objects compatability with Numpy or Python functions labels Oct 30, 2016
Update _Openpyxl20Writer and fixed _Openpyxl22Writer write_cells() methods. Made 20 index cells using numeric row/columns. Made 22 the same way as well (original state in current master)
Updated syntax to latest release openpyxl for retrieving cell values
@ditenberg
Copy link
Author

@TomAugspurger I put your suggested code into the pandas/io/tests/test_excel.py file and changed the cell value retrieval syntax in your mentioned location and a few others throughout the file. After running nosetests pandas/io/tests/test_excel.py I got back a clean report with no errors or UserWarnings.

@ditenberg
Copy link
Author

@TomAugspurger There are deeper issues with the _OpenpyxlXXWriter since they are deemed incompatible in the test_excel.py comments to be skipped during tests. Regardless, with commits the UserWarning no longer appears after test.

]

with ensure_clean('.xlsx') as path:
warnings.simplefilter('error', UserWarning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assert_produces_warning

self.sheets[sheet_name] = wks

for cell in cells:
colletter = get_column_letter(startcol + cell.col + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these changes need to be back-compat. so need to switch code based on the version.

@jreback
Copy link
Contributor

jreback commented Dec 21, 2016

@ditenberg can you rebase / update.

this needs to be back compat (easy enough, you simply have a version check on the import and branch based on that).

@jreback
Copy link
Contributor

jreback commented Jan 9, 2017

@ditenberg can you update this?

@jreback
Copy link
Contributor

jreback commented Jan 14, 2017

closing as stale, but would like you to update if possible.

@jreback jreback closed this Jan 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compat pandas objects compatability with Numpy or Python functions IO Excel read_excel, to_excel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COMPAT: openpyxl

3 participants