Skip to content

Commit 8a16900

Browse files
klonuojreback
authored andcommitted
BUG: to_clipboard output formatting (GH8305)
1 parent 391e90b commit 8a16900

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

doc/source/v0.15.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ Bug Fixes
966966
- Bug with messed variables in ``radviz`` visualization (:issue:`8199`).
967967
- Bug in interpolation methods with the ``limit`` keyword when no values needed interpolating (:issue:`7173`).
968968
- Bug where ``col_space`` was ignored in ``DataFrame.to_string()`` when ``header=False`` (:issue:`8230`).
969-
969+
- Bug in ``to_clipboard`` that would clip long column data (:issue:`8305`)
970970
- Bug in DataFrame terminal display: Setting max_column/max_rows to zero did not trigger auto-resizing of dfs to fit terminal width/height (:issue:`7180`).
971971
- Bug in OLS where running with "cluster" and "nw_lags" parameters did not work correctly, but also did not throw an error
972972
(:issue:`5884').

pandas/io/clipboard.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""" io on the clipboard """
2-
from pandas import compat, get_option, DataFrame
2+
from pandas import compat, get_option, option_context, DataFrame
33
from pandas.compat import StringIO
44

55

@@ -91,7 +91,8 @@ def to_clipboard(obj, excel=None, sep=None, **kwargs): # pragma: no cover
9191

9292
if isinstance(obj, DataFrame):
9393
# str(df) has various unhelpful defaults, like truncation
94-
objstr = obj.to_string()
94+
with option_context('display.max_colwidth', 999999):
95+
objstr = obj.to_string(**kwargs)
9596
else:
9697
objstr = str(obj)
9798
clipboard_set(objstr)

pandas/io/tests/test_clipboard.py

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def setUpClass(cls):
3535
cls.data['mixed'] = DataFrame({'a': np.arange(1.0, 6.0) + 0.01,
3636
'b': np.arange(1, 6),
3737
'c': list('abcde')})
38+
39+
# Test columns exceeding "max_colwidth" (GH8305)
40+
_cw = get_option('display.max_colwidth') + 1
41+
cls.data['colwidth'] = mkdf(5, 3, data_gen_f=lambda *args: 'x' * _cw,
42+
c_idx_type='s', r_idx_type='i',
43+
c_idx_names=[None], r_idx_names=[None])
3844
# Test GH-5346
3945
max_rows = get_option('display.max_rows')
4046
cls.data['longdf'] = mkdf(max_rows+1, 3, data_gen_f=lambda *args: randint(2),

0 commit comments

Comments
 (0)