|
5 | 5 |
|
6 | 6 | from io import BytesIO
|
7 | 7 | import os
|
| 8 | +import tempfile |
8 | 9 |
|
9 | 10 | import numpy as np
|
10 | 11 | import pytest
|
@@ -119,14 +120,12 @@ def _encode_data_with_bom(_data):
|
119 | 120 | tm.assert_frame_equal(result, expected)
|
120 | 121 |
|
121 | 122 |
|
122 |
| -@pytest.mark.parametrize("byte", [8, 16]) |
123 |
| -@pytest.mark.parametrize("fmt", ["utf-{0}", "utf_{0}", "UTF-{0}", "UTF_{0}"]) |
124 |
| -def test_read_csv_utf_aliases(all_parsers, byte, fmt): |
| 123 | +def test_read_csv_utf_aliases(all_parsers, utf_value, encoding_fmt): |
125 | 124 | # see gh-13549
|
126 | 125 | expected = DataFrame({"mb_num": [4.8], "multibyte": ["test"]})
|
127 | 126 | parser = all_parsers
|
128 | 127 |
|
129 |
| - encoding = fmt.format(byte) |
| 128 | + encoding = encoding_fmt.format(utf_value) |
130 | 129 | data = "mb_num,multibyte\n4.8,test".encode(encoding)
|
131 | 130 |
|
132 | 131 | result = parser.read_csv(BytesIO(data), encoding=encoding)
|
@@ -155,3 +154,19 @@ def test_binary_mode_file_buffers(all_parsers, csv_dir_path, fname, encoding):
|
155 | 154 | with open(fpath, mode="rb") as fb:
|
156 | 155 | result = parser.read_csv(fb, encoding=encoding)
|
157 | 156 | tm.assert_frame_equal(expected, result)
|
| 157 | + |
| 158 | + |
| 159 | +@pytest.mark.parametrize("pass_encoding", [True, False]) |
| 160 | +def test_encoding_temp_file(all_parsers, utf_value, encoding_fmt, pass_encoding): |
| 161 | + # see gh-24130 |
| 162 | + parser = all_parsers |
| 163 | + encoding = encoding_fmt.format(utf_value) |
| 164 | + |
| 165 | + expected = DataFrame({"foo": ["bar"]}) |
| 166 | + |
| 167 | + with tempfile.TemporaryFile(mode="w+", encoding=encoding) as f: |
| 168 | + f.write("foo\nbar") |
| 169 | + f.seek(0) |
| 170 | + |
| 171 | + result = parser.read_csv(f, encoding=encoding if pass_encoding else None) |
| 172 | + tm.assert_frame_equal(result, expected) |
0 commit comments