Last active
August 29, 2015 14:28
-
-
Save NapalmHorn/1ad1671de64c88088306 to your computer and use it in GitHub Desktop.
Code to "test" openpyxl pandas xlsx export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
import json | |
import numpy as np | |
import openpyxl | |
import pandas as pd | |
import string | |
import sys | |
def main(): | |
"""Code to "test" openpyxl pandas xlsx export""" | |
filename = "text.xlsx" | |
limit = 2 ** 8 | |
data = {} | |
cols = [] | |
for i in range(limit): | |
cols.append(make_label()) | |
for j in range(limit): | |
line = {} | |
for col in cols: | |
line[col] = np.random.random() | |
data[make_label()] = line | |
try: | |
frame = pd.DataFrame.from_dict(data) | |
frame.to_excel(filename) | |
except: | |
frame.to_json("dump.json") | |
raise | |
print "Test passed, openpyxl version:", openpyxl.__version__ | |
def make_label(): | |
"""generate lables for attempts to cause errors""" | |
name_letters = string.lowercase + string.uppercase + "_:/% " | |
return string.lowercase[np.random.choice(len(string.lowercase))] + \ | |
"".join([name_letters[np.random.choice(len(name_letters))] | |
for zed in range(11)]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment