Skip to content

Commit

Permalink
TST: enable csv tests for use_arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
theroggy committed Oct 20, 2024
1 parent ab3486e commit eee2e57
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pyogrio/tests/test_geopandas_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def spatialite_available(path):


@pytest.mark.parametrize("encoding", ["utf-8", "cp1252", None])
def test_read_csv_encoding(tmp_path, encoding):
def test_read_csv_encoding(tmp_path, encoding, use_arrow):
# Write csv test file. Depending on the os this will be written in a different
# encoding: for linux and macos this is utf-8, for windows it is cp1252.
csv_path = tmp_path / "test.csv"
Expand All @@ -105,7 +105,7 @@ def test_read_csv_encoding(tmp_path, encoding):
# Read csv. The data should be read with the same default encoding as the csv file
# was written in, but should have been converted to utf-8 in the dataframe returned.
# Hence, the asserts below, with strings in utf-8, be OK.
df = read_dataframe(csv_path, encoding=encoding)
df = read_dataframe(csv_path, encoding=encoding, use_arrow=use_arrow)

assert len(df) == 1
assert df.columns.tolist() == ["näme", "city"]
Expand All @@ -117,14 +117,14 @@ def test_read_csv_encoding(tmp_path, encoding):
locale.getpreferredencoding().upper() == "UTF-8",
reason="test requires non-UTF-8 default platform",
)
def test_read_csv_platform_encoding(tmp_path):
def test_read_csv_platform_encoding(tmp_path, use_arrow):
"""verify that read defaults to platform encoding; only works on Windows (CP1252)"""
csv_path = tmp_path / "test.csv"
with open(csv_path, "w", encoding=locale.getpreferredencoding()) as csv:
csv.write("näme,city\n")
csv.write("Wilhelm Röntgen,Zürich\n")

df = read_dataframe(csv_path)
df = read_dataframe(csv_path, use_arrow=use_arrow)

assert len(df) == 1
assert df.columns.tolist() == ["näme", "city"]
Expand Down Expand Up @@ -944,7 +944,8 @@ def test_read_sql_dialect_sqlite_gpkg(naturalearth_lowres, use_arrow):


@pytest.mark.parametrize("encoding", ["utf-8", "cp1252", None])
def test_write_csv_encoding(tmp_path, encoding):
@pytest.mark.requires_arrow_write_api
def test_write_csv_encoding(tmp_path, encoding, use_arrow):
"""Test if write_dataframe uses the default encoding correctly."""
# Write csv test file. Depending on the os this will be written in a different
# encoding: for linux and macos this is utf-8, for windows it is cp1252.
Expand All @@ -958,7 +959,7 @@ def test_write_csv_encoding(tmp_path, encoding):
# same encoding as above.
df = pd.DataFrame({"näme": ["Wilhelm Röntgen"], "city": ["Zürich"]})
csv_pyogrio_path = tmp_path / "test_pyogrio.csv"
write_dataframe(df, csv_pyogrio_path, encoding=encoding)
write_dataframe(df, csv_pyogrio_path, encoding=encoding, use_arrow=use_arrow)

# Check if the text files written both ways can be read again and give same result.
with open(csv_path, encoding=encoding) as csv:
Expand Down

0 comments on commit eee2e57

Please sign in to comment.