Skip to content

Commit

Permalink
Remove test_pickle_generalurl_read in favor of test_request_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Feb 4, 2025
1 parent e84a7f7 commit b0dade7
Showing 1 changed file with 0 additions and 49 deletions.
49 changes: 0 additions & 49 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,55 +383,6 @@ def test_pickle_buffer_roundtrip():
tm.assert_frame_equal(df, result)


# ---------------------
# tests for URL I/O
# ---------------------


@pytest.mark.parametrize(
"mockurl", ["http://url.com", "ftp://test.com", "http://gzip.com"]
)
def test_pickle_generalurl_read(monkeypatch, mockurl):
def python_pickler(obj, path):
with open(path, "wb") as fh:
pickle.dump(obj, fh, protocol=-1)

class MockReadResponse:
def __init__(self, path) -> None:
self.file = open(path, "rb")
if "gzip" in path:
self.headers = {"Content-Encoding": "gzip"}
else:
self.headers = {"Content-Encoding": ""}

def __enter__(self):
return self

def __exit__(self, *args):
self.close()

def read(self):
return self.file.read()

def close(self):
return self.file.close()

with tm.ensure_clean() as path:

def mock_urlopen_read(*args, **kwargs):
return MockReadResponse(path)

df = DataFrame(
1.1 * np.arange(120).reshape((30, 4)),
columns=Index(list("ABCD"), dtype=object),
index=Index([f"i-{i}" for i in range(30)], dtype=object),
)
python_pickler(df, path)
monkeypatch.setattr("urllib.request.urlopen", mock_urlopen_read)
result = pd.read_pickle(mockurl)
tm.assert_frame_equal(df, result)


def test_pickle_fsspec_roundtrip():
pytest.importorskip("fsspec")
with tm.ensure_clean():
Expand Down

0 comments on commit b0dade7

Please sign in to comment.