BUG: to_clipboard raises an error with null values in data frame
See original GitHub issueWith the latest version of pandas installed on windows, running the following code will raise an error:
df = pd.DataFrame(['\x00'])
df.to_clipboard(index=False, excel=False)
Here is the traceback:
ArgumentError Traceback (most recent call last)
<ipython-input-7-2549db3ae4d0> in <module> 1 df = pd.DataFrame([‘\x00’]) ----> 2 df.to_clipboard(index=False, excel=False)
e:\Anaconda\lib\site-packages\pandas\core\generic.py in to_clipboard(self, excel, sep, **kwargs) 3023 from pandas.io import clipboards 3024 -> 3025 clipboards.to_clipboard(self, excel=excel, sep=sep, **kwargs) 3026 3027 @final
e:\Anaconda\lib\site-packages\pandas\io\clipboards.py in to_clipboard(obj, excel, sep, **kwargs) 143 else: 144 objstr = str(obj) –> 145 clipboard_set(objstr)
e:\Anaconda\lib\site-packages\pandas\io\clipboard_init_.py in lazy_load_stub_copy(text) 631 global copy, paste 632 copy, paste = determine_clipboard() –> 633 return copy(text) 634 635
e:\Anaconda\lib\site-packages\pandas\io\clipboard_init_.py in copy_windows(text) 454 # the object must have been allocated using the 455 # function with the GMEM_MOVEABLE flag. –> 456 count = wcslen(text) + 1 457 handle = safeGlobalAlloc(GMEM_MOVEABLE, count * sizeof(c_wchar)) 458 locked_handle = safeGlobalLock(handle)
e:\Anaconda\lib\site-packages\pandas\io\clipboard_init_.py in call(self, *args) 306 307 def call(self, *args): –> 308 ret = self.f(*args) 309 if not ret and get_errno(): 310 raise PyperclipWindowsException("Error calling " + self.f.name)
ArgumentError: argument 1: <class ‘ValueError’>: embedded null character
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Might still be specific to different Windows OSes - see an issue like #38527 which only occurred for WSL 2.0
Hi! I use windows 10 and Python 3.8 and PyCharm professional 2020.3 . My computer uses CPU Intel core I5 9600k and 8G ram. I executed above codes and there wasn’t any error and I could print the data.