Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST/CLN: Replace all tmpdir / os.path operations in tests with pathlib.Path #411

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 30 additions & 42 deletions benchmarks/test_io_benchmarks_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,127 +60,115 @@ def test_read_dataframe_benchmark_geopandas_nhd_hr(nhd_hr, benchmark):

### Write lowres Admin 0
@pytest.mark.benchmark(group="write-geopandas-lowres-admin0")
def test_write_dataframe_benchmark_lowres_shp(tmpdir, naturalearth_lowres, benchmark):
def test_write_dataframe_benchmark_lowres_shp(tmp_path, naturalearth_lowres, benchmark):
df = read_dataframe(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(write_dataframe, df, filename, driver="ESRI Shapefile")
benchmark(write_dataframe, df, tmp_path / "test.shp", driver="ESRI Shapefile")


@pytest.mark.benchmark(group="write-geopandas-lowres-admin0")
def test_write_dataframe_benchmark_lowres_gpkg(tmpdir, naturalearth_lowres, benchmark):
def test_write_dataframe_benchmark_lowres_gpkg(tmp_path, naturalearth_lowres, benchmark):
df = read_dataframe(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.gpkg")
benchmark(write_dataframe, df, filename, driver="GPKG")
benchmark(write_dataframe, df, tmp_path / "test.gpkg", driver="GPKG")


@pytest.mark.benchmark(group="write-geopandas-lowres-admin0")
def test_write_dataframe_benchmark_lowres_geojson(
tmpdir, naturalearth_lowres, benchmark
tmp_path, naturalearth_lowres, benchmark
):
df = read_dataframe(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.json")
benchmark(write_dataframe, df, filename, driver="GeoJSON")
benchmark(write_dataframe, df, tmp_path / "test.json", driver="GeoJSON")


@pytest.mark.benchmark(group="write-geopandas-lowres-admin0")
def test_write_dataframe_benchmark_lowres_geojsonseq(
tmpdir, naturalearth_lowres, benchmark
tmp_path, naturalearth_lowres, benchmark
):
df = read_dataframe(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.json")
benchmark(write_dataframe, df, filename, driver="GeoJSONSeq")
benchmark(write_dataframe, df, tmp_path / "test.json", driver="GeoJSONSeq")


@pytest.mark.benchmark(group="write-geopandas-lowres-admin0")
def test_write_dataframe_benchmark_geopandas_lowres_shp(
tmpdir, naturalearth_lowres, benchmark
tmp_path, naturalearth_lowres, benchmark
):
df = gp.read_file(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(df.to_file, filename, driver="ESRI Shapefile")
benchmark(df.to_file, tmp_path / "test.shp", driver="ESRI Shapefile")


@pytest.mark.benchmark(group="write-geopandas-lowres-admin0")
def test_write_dataframe_benchmark_geopandas_lowres_gpkg(
tmpdir, naturalearth_lowres, benchmark
tmp_path, naturalearth_lowres, benchmark
):
df = gp.read_file(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(df.to_file, filename, driver="GPKG")
benchmark(df.to_file, tmp_path / "test.gpkg", driver="GPKG")


### Write modres Admin 0
@pytest.mark.benchmark(group="write-geopandas-modres-admin0")
def test_write_dataframe_benchmark_modres_shp(tmpdir, naturalearth_modres, benchmark):
def test_write_dataframe_benchmark_modres_shp(tmp_path, naturalearth_modres, benchmark):
df = read_dataframe(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(write_dataframe, df, filename, driver="ESRI Shapefile")
benchmark(write_dataframe, df, tmp_path / "test.shp", driver="ESRI Shapefile")


@pytest.mark.benchmark(group="write-geopandas-modres-admin0")
def test_write_dataframe_benchmark_modres_gpkg(tmpdir, naturalearth_modres, benchmark):
def test_write_dataframe_benchmark_modres_gpkg(tmp_path, naturalearth_modres, benchmark):
df = read_dataframe(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.gpkg")
benchmark(write_dataframe, df, filename, driver="GPKG")
benchmark(write_dataframe, df, tmp_path / "test.gpkg", driver="GPKG")


@pytest.mark.benchmark(group="write-geopandas-modres-admin0")
def test_write_dataframe_benchmark_modres_geojson(
tmpdir, naturalearth_modres, benchmark
tmp_path, naturalearth_modres, benchmark
):
df = read_dataframe(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.json")
benchmark(write_dataframe, df, filename, driver="GeoJSON")
benchmark(write_dataframe, df, tmp_path / "test.json", driver="GeoJSON")


@pytest.mark.benchmark(group="write-geopandas-modres-admin0")
def test_write_dataframe_benchmark_modres_geojsonseq(
tmpdir, naturalearth_modres, benchmark
tmp_path, naturalearth_modres, benchmark
):
df = read_dataframe(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.json")
benchmark(write_dataframe, df, filename, driver="GeoJSONSeq")
benchmark(write_dataframe, df, tmp_path / "test.json", driver="GeoJSONSeq")


@pytest.mark.benchmark(group="write-geopandas-modres-admin0")
def test_write_dataframe_benchmark_geopandas_modres_shp(
tmpdir, naturalearth_modres, benchmark
tmp_path, naturalearth_modres, benchmark
):
df = gp.read_file(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(df.to_file, filename, driver="ESRI Shapefile")
benchmark(df.to_file, tmp_path / "test.shp", driver="ESRI Shapefile")


@pytest.mark.benchmark(group="write-geopandas-modres-admin0")
def test_write_dataframe_benchmark_geopandas_modres_gpkg(
tmpdir, naturalearth_modres, benchmark
tmp_path, naturalearth_modres, benchmark
):
df = gp.read_file(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(df.to_file, filename, driver="GPKG")
benchmark(df.to_file, tmp_path / "test.gpkg", driver="GPKG")


### Write NHD
@pytest.mark.filterwarnings("ignore: RuntimeWarning")
@pytest.mark.benchmark(group="write-geopandas-nhd_hr")
def test_write_dataframe_benchmark_nhd_shp(tmpdir, nhd_hr, benchmark):
def test_write_dataframe_benchmark_nhd_shp(tmp_path, nhd_hr, benchmark):
layer = "NHDFlowline"
df = read_dataframe(nhd_hr, layer=layer)

# Datetime not currently supported
df = df.drop(columns="FDate")

filename = os.path.join(str(tmpdir), "test.shp")
benchmark(write_dataframe, df, filename, layer=layer, driver="ESRI Shapefile")
benchmark(write_dataframe, df, tmp_path / "test.shp", layer=layer, driver="ESRI Shapefile")


@pytest.mark.filterwarnings("ignore: RuntimeWarning")
@pytest.mark.benchmark(group="write-geopandas-nhd_hr")
def test_write_dataframe_benchmark_geopandas_nhd_shp(tmpdir, nhd_hr, benchmark):
def test_write_dataframe_benchmark_geopandas_nhd_shp(tmp_path, nhd_hr, benchmark):
layer = "NHDFlowline"
df = gp.read_file(nhd_hr, layer=layer)

# Datetime not currently supported by pyogrio, so drop here too so that the
# benchmark is fair.
df = df.drop(columns="FDate")

filename = os.path.join(str(tmpdir), "test.shp")
benchmark(df.to_file, filename, layer=layer, driver="ESRI Shapefile")
benchmark(df.to_file, tmp_path/"test.shp", layer=layer, driver="ESRI Shapefile")
45 changes: 18 additions & 27 deletions benchmarks/test_raw_io_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,83 +94,74 @@ def test_read_only_meta_modres1(naturalearth_modres1, benchmark):


@pytest.mark.benchmark(group="write-lowres")
def test_write_lowres_shp(tmpdir, naturalearth_lowres, benchmark):
def test_write_lowres_shp(tmp_path, naturalearth_lowres, benchmark):
meta, _, geometry, field_data = read(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(write, filename, geometry, field_data, driver="ESRI Shapefile", **meta)
benchmark(write, tmp_path / "test.shp", geometry, field_data, driver="ESRI Shapefile", **meta)


@pytest.mark.benchmark(group="write-lowres")
def test_write_lowres_gpkg(tmpdir, naturalearth_lowres, benchmark):
def test_write_lowres_gpkg(tmp_path, naturalearth_lowres, benchmark):
meta, _, geometry, field_data = read(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.gpkg")
benchmark(write, filename, geometry, field_data, driver="GPKG", **meta)
benchmark(write, tmp_path / "test.gpkg", geometry, field_data, driver="GPKG", **meta)


@pytest.mark.benchmark(group="write-lowres")
def test_write_lowres_geojson(tmpdir, naturalearth_lowres, benchmark):
def test_write_lowres_geojson(tmp_path, naturalearth_lowres, benchmark):
meta, _, geometry, field_data = read(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.json")
benchmark(write, filename, geometry, field_data, driver="GeoJSON", **meta)
benchmark(write, tmp_path / "test.json", geometry, field_data, driver="GeoJSON", **meta)


@pytest.mark.benchmark(group="write-lowres")
def test_write_lowres_geojsonseq(tmpdir, naturalearth_lowres, benchmark):
def test_write_lowres_geojsonseq(tmp_path, naturalearth_lowres, benchmark):
meta, _, geometry, field_data = read(naturalearth_lowres)
filename = os.path.join(str(tmpdir), "test.json")
benchmark(write, filename, geometry, field_data, driver="GeoJSONSeq", **meta)
benchmark(write, tmp_path / "test.json", geometry, field_data, driver="GeoJSONSeq", **meta)


@pytest.mark.benchmark(group="write-lowres")
def test_write_fiona_lowres_shp(tmpdir, naturalearth_lowres, benchmark):
def test_write_fiona_lowres_shp(tmp_path, naturalearth_lowres, benchmark):
with fiona.open(naturalearth_lowres) as source:
crs = source.crs
schema = source.schema
records = list(source)

filename = os.path.join(str(tmpdir), "test.shp")
benchmark(
fiona_write, filename, records, driver="ESRI Shapefile", crs=crs, schema=schema
fiona_write, tmp_path / "test.shp", records, driver="ESRI Shapefile", crs=crs, schema=schema
)


# @pytest.mark.benchmark(group="write-lowres")
# def test_write_fiona_lowres_gpkg(tmpdir, naturalearth_lowres, benchmark):
# def test_write_fiona_lowres_gpkg(tmp_path, naturalearth_lowres, benchmark):
# with fiona.open(naturalearth_lowres) as source:
# crs = source.crs
# schema = source.schema
# records = list(source)

# filename = os.path.join(str(tmpdir), "test.gpkg")
# benchmark(fiona_write, filename, records, driver="GPKG", crs=crs, schema=schema)
# benchmark(fiona_write, tmp_path / "test.gpkg", records, driver="GPKG", crs=crs, schema=schema)


# @pytest.mark.benchmark(group="write-lowres")
# def test_write_fiona_lowres_geojson(tmpdir, naturalearth_lowres, benchmark):
# def test_write_fiona_lowres_geojson(tmp_path, naturalearth_lowres, benchmark):
# with fiona.open(naturalearth_lowres) as source:
# crs = source.crs
# schema = source.schema
# records = list(source)

# filename = os.path.join(str(tmpdir), "test.json")
# benchmark(fiona_write, filename, records, driver="GeoJSON", crs=crs, schema=schema)
# benchmark(fiona_write, tmp_path / "test.json", records, driver="GeoJSON", crs=crs, schema=schema)


@pytest.mark.benchmark(group="write-modres")
def test_write_modres_shp(tmpdir, naturalearth_modres, benchmark):
def test_write_modres_shp(tmp_path, naturalearth_modres, benchmark):
meta, _, geometry, field_data = read(naturalearth_modres)
filename = os.path.join(str(tmpdir), "test.shp")
benchmark(write, filename, geometry, field_data, **meta)
benchmark(write, tmp_path / "test.shp", geometry, field_data, **meta)


@pytest.mark.benchmark(group="write-modres")
def test_write_fiona_modres_shp(tmpdir, naturalearth_modres, benchmark):
def test_write_fiona_modres_shp(tmp_path, naturalearth_modres, benchmark):
with fiona.open(naturalearth_modres) as source:
crs = source.crs
schema = source.schema
records = list(source)

filename = os.path.join(str(tmpdir), "test.shp")
benchmark(
fiona_write, filename, records, driver="ESRI Shapefile", crs=crs, schema=schema
fiona_write, tmp_path / "test.shp", records, driver="ESRI Shapefile", crs=crs, schema=schema
)
Loading