@@ -97,6 +97,17 @@ def test_to_read_gcs(gcs_buffer, format):
97
97
tm .assert_frame_equal (df1 , df2 )
98
98
99
99
100
+ def assert_equal_zip_safe (result : bytes , expected : bytes ):
101
+ """
102
+ We would like to assert these are equal, but the 11th byte is a last-modified
103
+ timestamp, which in some builds is off-by-one, so we check around that.
104
+
105
+ See https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers
106
+ """
107
+ assert result [:10 ] == expected [:10 ]
108
+ assert result [11 :] == expected [11 :]
109
+
110
+
100
111
@td .skip_if_no ("gcsfs" )
101
112
@pytest .mark .parametrize ("encoding" , ["utf-8" , "cp1251" ])
102
113
def test_to_csv_compression_encoding_gcs (gcs_buffer , compression_only , encoding ):
@@ -121,7 +132,10 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
121
132
# write compressed file with explicit compression
122
133
path_gcs = "gs://test/test.csv"
123
134
df .to_csv (path_gcs , compression = compression , encoding = encoding )
124
- assert gcs_buffer .getvalue () == buffer .getvalue ()
135
+ res = gcs_buffer .getvalue ()
136
+ expected = buffer .getvalue ()
137
+ assert_equal_zip_safe (res , expected )
138
+
125
139
read_df = read_csv (
126
140
path_gcs , index_col = 0 , compression = compression_only , encoding = encoding
127
141
)
@@ -136,11 +150,7 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
136
150
137
151
res = gcs_buffer .getvalue ()
138
152
expected = buffer .getvalue ()
139
- # We would like to assert these are equal, but the 11th byte is a last-modified
140
- # timestamp, which in some builds is off-by-one, so we check around that
141
- # See https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers
142
- assert res [:10 ] == expected [:10 ]
143
- assert res [11 :] == expected [11 :]
153
+ assert_equal_zip_safe (res , expected )
144
154
145
155
read_df = read_csv (path_gcs , index_col = 0 , compression = "infer" , encoding = encoding )
146
156
tm .assert_frame_equal (df , read_df )
0 commit comments