@@ -60,30 +60,17 @@ def __init__(
60
60
if path_or_buf is None :
61
61
path_or_buf = StringIO ()
62
62
63
- # Extract compression mode as given, if dict
64
- compression , self .compression_args = get_compression_method (compression )
65
- self .compression = infer_compression (path_or_buf , compression )
66
-
67
63
ioargs = get_filepath_or_buffer (
68
64
path_or_buf ,
69
65
encoding = encoding ,
70
- compression = self . compression ,
66
+ compression = compression ,
71
67
mode = mode ,
72
68
storage_options = storage_options ,
73
69
)
74
70
self .path_or_buf = ioargs .filepath_or_buffer
75
71
self .should_close = ioargs .should_close
76
72
self .mode = ioargs .mode
77
73
78
- # GH21227 internal compression is not used for non-binary handles.
79
- if compression and hasattr (self .path_or_buf , "write" ) and "b" not in self .mode :
80
- warnings .warn (
81
- "compression has no effect when passing a non-binary object as input." ,
82
- RuntimeWarning ,
83
- stacklevel = 2 ,
84
- )
85
- compression = None
86
-
87
74
self .sep = sep
88
75
self .na_rep = na_rep
89
76
self .float_format = float_format
@@ -93,6 +80,7 @@ def __init__(
93
80
self .index_label = index_label
94
81
self .encoding = encoding or "utf-8"
95
82
self .errors = errors
83
+ self .compression = compression
96
84
self .quoting = quoting or csvlib .QUOTE_MINIMAL
97
85
self .quotechar = quotechar
98
86
self .doublequote = doublequote
@@ -106,6 +94,27 @@ def __init__(
106
94
ncols = self .obj .shape [- 1 ]
107
95
self .data = [None ] * ncols
108
96
97
+ @property
98
+ def compression (self ):
99
+ return self ._compression
100
+
101
+ @compression .setter
102
+ def compression (self , compression ):
103
+ # Extract compression mode as given, if dict
104
+ compression , self .compression_args = get_compression_method (compression )
105
+ compression = infer_compression (self .path_or_buf , compression )
106
+
107
+ # GH21227 internal compression is not used for non-binary handles.
108
+ if compression and hasattr (self .path_or_buf , "write" ) and "b" not in self .mode :
109
+ warnings .warn (
110
+ "compression has no effect when passing a non-binary object as input." ,
111
+ RuntimeWarning ,
112
+ stacklevel = 2 ,
113
+ )
114
+ compression = None
115
+
116
+ self ._compression = compression
117
+
109
118
@property
110
119
def index_label (self ):
111
120
return self ._index_label
0 commit comments