pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.7k stars 17.92k forks source link

copy of pd.ExcelWriter #17258

Closed Phaust94 closed 7 years ago

Phaust94 commented 7 years ago

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd
import copy
writer = pd.ExcelWriter('result.xlsx')
cp = copy.deepcopy(writer)
print(cp.path)

Problem description

For some reason it throws an error, which it shouldn't. It throws this error: TypeError: new() missing 1 required positional argument: 'path'

Expected Output

'result.xlsx'

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.2.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None pandas: 0.20.3 pytest: None pip: 9.0.1 setuptools: 27.2.0 Cython: 0.26 numpy: 1.13.1 scipy: 0.19.1 xarray: None IPython: None sphinx: None patsy: 0.4.1 dateutil: 2.6.1 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: 2.6.2 feather: None matplotlib: 2.0.2 openpyxl: 2.4.8 xlrd: 1.0.0 xlwt: None xlsxwriter: 0.9.6 lxml: None bs4: None html5lib: None sqlalchemy: None pymysql: None psycopg2: None jinja2: None s3fs: None pandas_gbq: None pandas_datareader: None
chris-b1 commented 7 years ago

Why are you copying an ExcelWriter - not any reason I can think of do that?

Even if we did support this, it wouldn't really work - each copy would hold a separate xlsxwriter handle to the file and would overwrite the others' changes.

In [9]: import xlsxwriter

In [10]: from xlsxwriter import Workbook

In [11]: wb = Workbook('result.xlsx')

In [12]: wb2 = Workbook('result.xlsx')

In [13]: wb.add_worksheet('tmp1')
Out[13]: <xlsxwriter.worksheet.Worksheet at 0xc6f1278>

In [14]: wb.close()

# overwrites what was done with wb
In [15]: wb2.close()
jreback commented 7 years ago

closing as won't fix. This is a mis-use of the API.