-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make "copy" work better with numpy arrays #2577
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,8 @@ | |
from spyderlib.widgets.texteditor import TextEditor | ||
from spyderlib.widgets.importwizard import ImportWizard | ||
from spyderlib.py3compat import (to_text_string, to_binary_string, | ||
is_text_string, is_binary_string, getcwd, u) | ||
is_text_string, is_binary_string, getcwd, u, | ||
PY3, io) | ||
|
||
|
||
LARGE_NROWS = 5000 | ||
|
@@ -1075,7 +1076,23 @@ def copy(self): | |
for idx in self.selectedIndexes(): | ||
if not idx.isValid(): | ||
continue | ||
clipl.append(to_text_string(self.delegate.get_value(idx))) | ||
obj = self.delegate.get_value(idx) | ||
# check if it's a numpy array, and if so make sure to copy the whole | ||
# thing in a tab separated format | ||
try: | ||
import numpy as np | ||
except ImportError: | ||
pass # skip this part | ||
else: | ||
if isinstance(obj, np.ndarray): | ||
if PY3: | ||
output = io.BytesIO() | ||
else: | ||
output = io.StringIO() | ||
np.savetxt(output, obj, delimiter='\t') | ||
obj = output.getvalue().decode('utf-8') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is not needed. That's why you're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, forget my comment, this is really necessary :-) |
||
|
||
clipl.append(to_text_string(obj)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is use of
because |
||
clipboard.setText(u('\n').join(clipl)) | ||
|
||
def import_from_string(self, text, title=None): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this
try/except
is not needed. If Numpy arrays are shown in the Variable Explorer, that meansnumpy
is already present, so we don't need to verify for its presence.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need it to check if the object is a ndarray. You you need it in order to know if you need it !