Skip to content

Commit

Permalink
BREAKING CHANGE: Remove all deprecations from sertit==1.* #3
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Dec 13, 2024
1 parent fd953c2 commit 455716a
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 682 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 2.0.0 (20xx-xx-xx)

- **BREAKING CHANGE**: Remove all deprecations from `sertit==1.*` ([#3](https://github.com/sertit/sertit-utils/issues/3)):
- Duplication between `path` and `files` modules
- Duplication between `ci`, `s3` and `unistra` modules
- Arguments in functions
- Renaming functions
- Others
- **ENH: Use `universal_pathlib` instead of `cloudpathlib` (even if the code is still compatible with `cloudpathlib`)** ([#4](https://github.com/sertit/sertit-utils/issues/4))

## 1.44.x (20xx-xx-xx)
Expand Down
5 changes: 0 additions & 5 deletions CI/SCRIPTS/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from datetime import date, datetime

import numpy as np
import pytest

from CI.SCRIPTS.script_utils import Polarization
from sertit import AnyPath, ci, files
Expand Down Expand Up @@ -93,10 +92,6 @@ def test_json():
) # Enum are stored following their value
assert obj == test_dict

# Test deprecation
with pytest.deprecated_call():
files.save_json(json_file, test_dict)


def test_pickle():
"""Test pickle functions"""
Expand Down
52 changes: 0 additions & 52 deletions CI/SCRIPTS/test_rasters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
INT8_NODATA,
UINT8_NODATA,
UINT16_NODATA,
any_raster_to_xr_ds,
get_nodata_value_from_dtype,
get_nodata_value_from_xr,
)
from sertit.vectors import EPSG_4326
Expand Down Expand Up @@ -675,11 +673,6 @@ def test_write(dtype, nodata_val, tmp_path, xda):
)
_test_raster_after_write(test_path, dtype, nodata_val)

# test deprecation warning
test_deprecated_path = os.path.join(tmp_path, "test_depr.tif")
with pytest.deprecated_call():
rasters.write(xda, path=test_deprecated_path, dtype=dtype)


def test_dim():
"""Test on BEAM-DIMAP function"""
Expand Down Expand Up @@ -900,51 +893,6 @@ def test_rasterize(tmp_path, raster_path):
ci.assert_raster_almost_equal(raster_true_path, out_path, decimal=4)


@s3_env
def test_decorator_deprecation(raster_path):
from sertit.rasters import path_xarr_dst

@any_raster_to_xr_ds
def _ok_rasters(xds):
assert isinstance(xds, xr.DataArray)
return xds

@path_xarr_dst
def _depr_rasters(xds):
assert isinstance(xds, xr.DataArray)
return xds

# Not able to warn deprecation from inside the decorator
xr.testing.assert_equal(_ok_rasters(raster_path), _depr_rasters(raster_path))


def test_get_nodata_deprecation():
"""Test deprecation of get_nodata_value"""
# Test deprecation
for dtype in [
np.uint8,
np.int8,
np.uint16,
np.uint32,
np.int32,
np.int64,
np.uint64,
int,
"int",
np.int16,
np.float32,
np.float64,
float,
"float",
]:
with pytest.deprecated_call():
from sertit.rasters import get_nodata_value

ci.assert_val(
get_nodata_value_from_dtype(dtype), get_nodata_value(dtype), dtype
)


@s3_env
@dask_env
def test_get_notata_from_xr(raster_path):
Expand Down
54 changes: 0 additions & 54 deletions CI/SCRIPTS/test_rasters_rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from CI.SCRIPTS.script_utils import KAPUT_KWARGS, rasters_path, s3_env
from sertit import ci, rasters_rio, vectors
from sertit.rasters_rio import any_raster_to_rio_ds, get_nodata_value_from_dtype
from sertit.vectors import EPSG_4326

ci.reduce_verbosity()
Expand Down Expand Up @@ -421,56 +420,3 @@ def _test_idx(idx_list):
_test_idx([1])
_test_idx([1, 2])
_test_idx(1)


@s3_env
def test_decorator_deprecation(raster_path):
from sertit.rasters_rio import path_arr_dst

@any_raster_to_rio_ds
def _ok_rasters(ds):
return ds.read()

@path_arr_dst
def _depr_rasters(ds):
return ds.read()

# Not able to warn deprecation from inside the decorator
np.testing.assert_equal(_ok_rasters(raster_path), _depr_rasters(raster_path))


def test_get_nodata_deprecation():
"""Test deprecation of get_nodata_value"""
# Test deprecation
for dtype in [
np.uint8,
np.int8,
np.uint16,
np.uint32,
np.int32,
np.int64,
np.uint64,
int,
"int",
np.int16,
np.float32,
np.float64,
float,
"float",
]:
with pytest.deprecated_call():
from sertit.rasters_rio import get_nodata_value

ci.assert_val(
get_nodata_value_from_dtype(dtype), get_nodata_value(dtype), dtype
)


@s3_env
def test_write_deprecated(tmp_path, raster_path):
test_deprecated_path = os.path.join(tmp_path, "test_depr.tif")
raster, mtd = rasters_rio.read(raster_path)

# test deprecation warning
with pytest.deprecated_call():
rasters_rio.write(raster, mtd, path=test_deprecated_path)
10 changes: 0 additions & 10 deletions CI/SCRIPTS/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import geopandas as gpd
import pytest
from rasterio import CRS
from shapely import wkt

from CI.SCRIPTS.script_utils import KAPUT_KWARGS, files_path, s3_env, vectors_path
Expand Down Expand Up @@ -81,15 +80,6 @@ def test_vectors():
aoi = vectors.read(kml_path, **KAPUT_KWARGS)
_assert_attributes(aoi, kml_path)

with pytest.deprecated_call():
assert (
vectors.corresponding_utm_projection(aoi.centroid.x, aoi.centroid.y)
== "EPSG:32638"
)
assert CRS.from_string("EPSG:32638") == vectors.to_utm_crs(
aoi.centroid.x, aoi.centroid.y
)

env = aoi.envelope[0]

# Test kwargs (should be slightly not equal toi AOI to prove bbox does sth)
Expand Down
20 changes: 1 addition & 19 deletions sertit/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lxml import etree, html
from tqdm import tqdm

from sertit import AnyPath, logs, path, s3
from sertit import AnyPath, path, s3
from sertit.logs import SU_NAME
from sertit.types import AnyPathStrType, AnyPathType

Expand Down Expand Up @@ -222,12 +222,6 @@ def read_archived_xml(
>>> read_archived_xml(arch_path, file_regex)
<Element LANDSAT_METADATA_FILE at 0x1c90007f8c8>
"""
if regex is None:
logs.deprecation_warning(
"'xml_regex' is deprecated, please use 'regex' instead."
)
regex = kwargs.pop("xml_regex")

xml_bytes = read_archived_file(archive_path, regex=regex, file_list=file_list)

return etree.fromstring(xml_bytes)
Expand Down Expand Up @@ -455,12 +449,6 @@ def get_archived_path(
>>> path = get_archived_path(arch_path, file_regex)
'dir/filename.tif'
"""
if regex is None:
logs.deprecation_warning(
"'file_regex' is deprecated, please use 'regex' instead."
)
regex = kwargs.pop("file_regex")

# Get file list
archive_path = AnyPath(archive_path)

Expand Down Expand Up @@ -525,12 +513,6 @@ def get_archived_rio_path(
>>> rasterio.open(path)
<open DatasetReader name='zip+file://D:/path/to/output.zip!dir/filename.tif' mode='r'>
"""
if regex is None:
logs.deprecation_warning(
"'file_regex' is deprecated, please use 'regex' instead."
)
regex = kwargs.pop("file_regex")

archive_path = AnyPath(archive_path)
if archive_path.suffix in [".tar", ".zip"]:
prefix = archive_path.suffix[-3:]
Expand Down
28 changes: 0 additions & 28 deletions sertit/arcpy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
import logging.handlers

from sertit.logs import deprecation_warning

# Arcpy types from inside a schema
SHORT = "int32:4"
""" 'Short' type for ArcGis GDB """
Expand Down Expand Up @@ -153,32 +151,6 @@ def emit(self, record):
super(ArcPyLogHandler, self).emit(record)


def feature_layer_to_path(feature_layer) -> str:
"""
.. deprecated:: 1.36.0
Use :py:func:`gp_layer_to_path` instead.
Use :func:`gp_layer_to_path` instead.
Convert a feature layer to its source path.
Args:
feature_layer: Feature layer
Returns:
str: Path to the feature layer source
"""
deprecation_warning("This function is deprecated. Use gp_layer_to_path instead.")
# Get path
if hasattr(feature_layer, "dataSource"):
path = feature_layer.dataSource
else:
path = str(feature_layer)

return path


def gp_layer_to_path(feature_layer) -> str:
"""
Convert a GP layer to its source path.
Expand Down
59 changes: 2 additions & 57 deletions sertit/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from shapely import force_2d, normalize
from shapely.testing import assert_geometries_equal

from sertit import AnyPath, files, path, s3, unistra
from sertit.logs import SU_NAME, deprecation_warning
from sertit import AnyPath, files, path, s3
from sertit.logs import SU_NAME
from sertit.types import AnyPathStrType, AnyXrDataStructure

LOGGER = logging.getLogger(SU_NAME)
Expand All @@ -43,61 +43,6 @@
AWS_S3_ENDPOINT = s3.AWS_S3_ENDPOINT


def s3_env(*args, **kwargs):
"""
.. deprecated:: 1.30.0
Import it from :py:mod:`sertit.unistra` instead of :py:mod:`sertit.ci`
"""
deprecation_warning(
"This function is deprecated. Import it from 'sertit.unistra' instead of 'sertit.ci'"
)
return unistra.s3_env(*args, **kwargs)


def define_s3_client():
"""
.. deprecated:: 1.30.0
Import it from :py:mod:`sertit.unistra` instead of :py:mod:`sertit.ci`
"""
deprecation_warning(
"This function is deprecated. Import it from 'sertit.unistra' instead of 'sertit.ci'"
)
return unistra.define_s3_client()


def get_db2_path():
"""
.. deprecated:: 1.30.0
Import it from :py:mod:`sertit.unistra` instead of :py:mod:`sertit.ci`
"""
deprecation_warning(
"This function is deprecated. Import it from 'sertit.unistra' instead of 'sertit.ci'"
)
return unistra.get_db2_path()


def get_db3_path():
"""
.. deprecated:: 1.30.0
Import it from :py:mod:`sertit.unistra` instead of :py:mod:`sertit.ci`
"""
deprecation_warning(
"This function is deprecated. Import it from 'sertit.unistra' instead of 'sertit.ci'"
)
return unistra.get_db3_path()


def get_db4_path():
"""
.. deprecated:: 1.30.0
Import it from :py:mod:`sertit.unistra` instead of :py:mod:`sertit.ci`
"""
deprecation_warning(
"This function is deprecated. Import it from 'sertit.unistra' instead of 'sertit.ci'"
)
return unistra.get_db4_path()


def assert_val(val_1: Any, val_2: Any, field: str) -> None:
"""
Compare two values corresponding to a field
Expand Down
Loading

0 comments on commit 455716a

Please sign in to comment.