Skip to content

Commit d0fa9ce

Browse files
committed
Remove disallow_any_unimported from mypy, removed related type: ignore comments, addressed some mypy warnings related to Number type used
1 parent 1e2cba1 commit d0fa9ce

22 files changed

+42
-59
lines changed

eis_toolkit/checks/dataframe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@beartype
7-
def check_columns_valid(df: pd.DataFrame, columns: Sequence[str]) -> bool: # type: ignore[no-any-unimported]
7+
def check_columns_valid(df: pd.DataFrame, columns: Sequence[str]) -> bool:
88
"""
99
Check that all specified columns are in the dataframe.
1010
@@ -19,7 +19,7 @@ def check_columns_valid(df: pd.DataFrame, columns: Sequence[str]) -> bool: # ty
1919

2020

2121
@beartype
22-
def check_columns_numeric(df: pd.DataFrame, columns: Sequence[str]) -> bool: # type: ignore[no-any-unimported]
22+
def check_columns_numeric(df: pd.DataFrame, columns: Sequence[str]) -> bool:
2323
"""
2424
Check that all specified columns are numeric.
2525

eis_toolkit/checks/parameter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def check_numeric_value_sign(parameter_value: Number) -> bool:
3232
Returns:
3333
True if parameter value is positive, False if not
3434
"""
35-
if parameter_value > 0:
35+
if parameter_value > 0: # type: ignore
3636
return True
3737
else:
3838
return False

eis_toolkit/checks/raster.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@beartype
9-
def check_matching_cell_size( # type: ignore[no-any-unimported]
9+
def check_matching_cell_size(
1010
rasters: Sequence[rasterio.io.DatasetReader],
1111
) -> bool:
1212
"""Check if all input rasters have matching cell size.
@@ -26,7 +26,7 @@ def check_matching_cell_size( # type: ignore[no-any-unimported]
2626

2727

2828
@beartype
29-
def check_matching_pixel_alignment( # type: ignore[no-any-unimported]
29+
def check_matching_pixel_alignment(
3030
rasters: Sequence[rasterio.io.DatasetReader],
3131
) -> bool:
3232
"""Check if all input rasters have matching cell size and matching pixel alignment.
@@ -53,7 +53,7 @@ def check_matching_pixel_alignment( # type: ignore[no-any-unimported]
5353

5454

5555
@beartype
56-
def check_matching_bounds( # type: ignore[no-any-unimported]
56+
def check_matching_bounds(
5757
rasters: Sequence[rasterio.io.DatasetReader],
5858
) -> bool:
5959
"""Check if all input rasters have matching bounds.
@@ -73,9 +73,7 @@ def check_matching_bounds( # type: ignore[no-any-unimported]
7373

7474

7575
@beartype
76-
def check_raster_grids( # type: ignore[no-any-unimported]
77-
rasters: Sequence[rasterio.io.DatasetReader], same_extent: bool = False
78-
) -> bool:
76+
def check_raster_grids(rasters: Sequence[rasterio.io.DatasetReader], same_extent: bool = False) -> bool:
7977
"""
8078
Check all input rasters for matching gridding and optionally matching bounds.
8179

eis_toolkit/conversions/csv_to_geodataframe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515

16-
def _csv_to_geodataframe( # type: ignore[no-any-unimported]
16+
def _csv_to_geodataframe(
1717
csv: Path,
1818
indexes: Sequence[int],
1919
target_crs: int,
@@ -77,7 +77,7 @@ def _csv_to_geodataframe( # type: ignore[no-any-unimported]
7777

7878

7979
@beartype
80-
def csv_to_geodataframe( # type: ignore[no-any-unimported]
80+
def csv_to_geodataframe(
8181
csv: Path,
8282
indexes: Sequence[int],
8383
target_crs: int,

eis_toolkit/conversions/raster_to_dataframe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from beartype.typing import Sequence
88

99

10-
def _raster_to_dataframe( # type: ignore[no-any-unimported]
10+
def _raster_to_dataframe(
1111
raster: rasterio.io.DatasetReader,
1212
bands: Optional[Sequence[int]],
1313
add_coordinates: bool,
@@ -31,7 +31,7 @@ def _raster_to_dataframe( # type: ignore[no-any-unimported]
3131

3232

3333
@beartype
34-
def raster_to_dataframe( # type: ignore[no-any-unimported]
34+
def raster_to_dataframe(
3535
raster: rasterio.io.DatasetReader,
3636
bands: Optional[Sequence[int]] = None,
3737
add_coordinates: bool = False,

eis_toolkit/exploratory_analyses/pca.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
from eis_toolkit.exceptions import EmptyDataFrameException, InvalidParameterValueException
99

1010

11-
def _compute_pca( # type: ignore[no-any-unimported]
12-
data: pd.DataFrame, number_of_components: int
13-
) -> Tuple[pd.DataFrame, np.ndarray]:
11+
def _compute_pca(data: pd.DataFrame, number_of_components: int) -> Tuple[pd.DataFrame, np.ndarray]:
1412

1513
feature_matrix = data.loc[:, data.columns].values
1614
standardized_data = StandardScaler().fit_transform(feature_matrix)
@@ -26,9 +24,7 @@ def _compute_pca( # type: ignore[no-any-unimported]
2624

2725

2826
@beartype
29-
def compute_pca( # type: ignore[no-any-unimported]
30-
data: pd.DataFrame, number_of_components: int
31-
) -> Tuple[pd.DataFrame, np.ndarray]:
27+
def compute_pca(data: pd.DataFrame, number_of_components: int) -> Tuple[pd.DataFrame, np.ndarray]:
3228
"""
3329
Compute the principal components for the input data.
3430

eis_toolkit/exploratory_analyses/plot_pca.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@beartype
10-
def plot_pca( # type: ignore[no-any-unimported]
10+
def plot_pca(
1111
pca_df: pd.DataFrame, explained_variances: np.ndarray, color_feat: Optional[pd.Series] = None, save_path: str = ""
1212
) -> Figure:
1313
"""Plot a scatter matrix of different principal component combinations.

eis_toolkit/raster_processing/clipping.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212

1313
# The core clipping functionality. Used internally by clip.
14-
def _clip_raster( # type: ignore[no-any-unimported] # noqa: E261
15-
raster: rasterio.io.DatasetReader, geometries: Sequence
16-
) -> Tuple[np.ndarray, dict]:
14+
def _clip_raster(raster: rasterio.io.DatasetReader, geometries: Sequence) -> Tuple[np.ndarray, dict]:
1715
out_image, out_transform = mask(dataset=raster, shapes=geometries, crop=True, all_touched=True)
1816
out_meta = raster.meta.copy()
1917
out_meta.update(
@@ -24,9 +22,7 @@ def _clip_raster( # type: ignore[no-any-unimported] # noqa: E261
2422

2523

2624
@beartype
27-
def clip_raster( # type: ignore[no-any-unimported] # noqa: E261,E262
28-
raster: rasterio.io.DatasetReader, geodataframe: geopandas.GeoDataFrame
29-
) -> Tuple[np.ndarray, dict]:
25+
def clip_raster(raster: rasterio.io.DatasetReader, geodataframe: geopandas.GeoDataFrame) -> Tuple[np.ndarray, dict]:
3026
"""Clips a raster with polygon geometries.
3127
3228
Args:

eis_toolkit/raster_processing/extract_values_from_raster.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from eis_toolkit.exceptions import NonMatchinParameterLengthsException
1111

1212

13-
def _extract_values_from_raster( # type: ignore[no-any-unimported]
13+
def _extract_values_from_raster(
1414
raster_list: Sequence[rasterio.io.DatasetReader],
1515
geodataframe: gpd.GeoDataFrame,
1616
raster_column_names: Optional[Sequence[str]],
@@ -43,7 +43,7 @@ def _extract_values_from_raster( # type: ignore[no-any-unimported]
4343

4444

4545
@beartype
46-
def extract_values_from_raster( # type: ignore[no-any-unimported]
46+
def extract_values_from_raster(
4747
raster_list: Sequence[rasterio.io.DatasetReader],
4848
geodataframe: gpd.GeoDataFrame,
4949
raster_column_names: Optional[Sequence[str]] = None,

eis_toolkit/raster_processing/reprojecting.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
# Core reprojecting functionality used internally by reproject_raster and reproject_and_write_raster
11-
def _reproject_raster( # type: ignore[no-any-unimported]
11+
def _reproject_raster(
1212
raster: rasterio.io.DatasetReader, target_crs: int, resampling_method: warp.Resampling
1313
) -> Tuple[np.ndarray, dict]:
1414

@@ -53,7 +53,7 @@ def _reproject_raster( # type: ignore[no-any-unimported]
5353

5454

5555
@beartype
56-
def reproject_raster( # type: ignore[no-any-unimported]
56+
def reproject_raster(
5757
raster: rasterio.io.DatasetReader, target_crs: int, resampling_method: warp.Resampling = warp.Resampling.nearest
5858
) -> Tuple[np.ndarray, dict]:
5959
"""Reprojects raster to match given coordinate reference system (EPSG).

eis_toolkit/raster_processing/resampling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# The core resampling functionality. Used internally by resample.
15-
def _resample( # type: ignore[no-any-unimported]
15+
def _resample(
1616
raster: rasterio.io.DatasetReader,
1717
resampling_method: Resampling,
1818
upscale_factor: Number,
@@ -44,7 +44,7 @@ def _resample( # type: ignore[no-any-unimported]
4444

4545

4646
@beartype
47-
def resample( # type: ignore[no-any-unimported]
47+
def resample(
4848
raster: rasterio.io.DatasetReader,
4949
upscale_factor: Number,
5050
upscale_factor_y: Optional[Number] = None,

eis_toolkit/raster_processing/snapping.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111

1212
# The core snapping functionality. Used internally by snap.
13-
def _snap( # type: ignore[no-any-unimported]
14-
raster: rasterio.DatasetReader, snap_raster: rasterio.DatasetReader
15-
) -> Tuple[np.ndarray, dict]:
13+
def _snap(raster: rasterio.DatasetReader, snap_raster: rasterio.DatasetReader) -> Tuple[np.ndarray, dict]:
1614
raster_bounds = raster.bounds
1715
snap_bounds = snap_raster.bounds
1816
raster_pixel_size_x = raster.transform.a
@@ -66,9 +64,7 @@ def _snap( # type: ignore[no-any-unimported]
6664

6765

6866
@beartype
69-
def snap_with_raster( # type: ignore[no-any-unimported]
70-
raster: rasterio.DatasetReader, snap_raster: rasterio.DatasetReader
71-
) -> Tuple[np.ndarray, dict]:
67+
def snap_with_raster(raster: rasterio.DatasetReader, snap_raster: rasterio.DatasetReader) -> Tuple[np.ndarray, dict]:
7268
"""Snaps/aligns raster to given snap raster.
7369
7470
Raster is snapped from its left-bottom corner to nearest snap raster grid corner in left-bottom direction.

eis_toolkit/raster_processing/unifying.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from eis_toolkit.exceptions import InvalidParameterValueException
99

1010

11-
def _unify_raster_grids( # type: ignore[no-any-unimported]
11+
def _unify_raster_grids(
1212
base_raster: rasterio.io.DatasetReader,
1313
rasters_to_unify: Sequence[rasterio.io.DatasetReader],
1414
resampling_method: Resampling,
@@ -85,7 +85,7 @@ def _unify_raster_grids( # type: ignore[no-any-unimported]
8585

8686

8787
@beartype
88-
def unify_raster_grids( # type: ignore[no-any-unimported]
88+
def unify_raster_grids(
8989
base_raster: rasterio.io.DatasetReader,
9090
rasters_to_unify: Sequence[rasterio.io.DatasetReader],
9191
resampling_method: Resampling = Resampling.nearest,

eis_toolkit/raster_processing/windowing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from eis_toolkit.exceptions import CoordinatesOutOfBoundsException, InvalidParameterValueException
1111

1212

13-
def _extract_window( # type: ignore[no-any-unimported]
13+
def _extract_window(
1414
raster: rasterio.io.DatasetReader,
1515
center_coords: Tuple[Number, Number],
1616
height: int,
@@ -79,7 +79,7 @@ def _extract_window( # type: ignore[no-any-unimported]
7979

8080

8181
@beartype
82-
def extract_window( # type: ignore[no-any-unimported]
82+
def extract_window(
8383
raster: rasterio.io.DatasetReader,
8484
center_coords: Tuple[Number, Number],
8585
height: int,

eis_toolkit/utilities/miscellaneous.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def replace_values(
2626
Raster data with replaced values.
2727
"""
2828
out_data = data.copy()
29-
return np.where(np.isin(out_data, values_to_replace), replace_value, out_data)
29+
return np.where(np.isin(out_data, values_to_replace), replace_value, out_data) # type: ignore
3030

3131

3232
@beartype

eis_toolkit/utilities/nodata.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def set_nodata_raster_meta(raster_meta: Dict, nodata_value: Number) -> Dict:
3131

3232
@beartype
3333
def replace_raster_nodata_each_band(
34-
raster_data: np.ndarray, nodata_per_band: Dict[int, Union[Number, Sequence[Number]]], new_nodata: Number = -9999
34+
raster_data: np.ndarray,
35+
nodata_per_band: Dict[int, Union[Number, Sequence[Number]]],
36+
new_nodata: Number = -9999, # type: ignore
3537
) -> np.ndarray:
3638
"""
3739
Replace old nodata values with a new nodata value in a raster for each band separately.
@@ -72,7 +74,7 @@ def nodata_to_nan(data: np.ndarray, nodata_value: Number) -> np.ndarray:
7274
Returns:
7375
Input array where specified nodata has been converted to np.nan.
7476
"""
75-
return np.where(np.isin(data, nodata_value), np.nan, data)
77+
return np.where(np.isin(data, nodata_value), np.nan, data) # type: ignore
7678

7779

7880
@beartype
@@ -86,7 +88,7 @@ def nan_to_nodata(data: np.ndarray, nodata_value: Number) -> np.ndarray:
8688
Returns:
8789
Input array where np.nan has been converted to specified nodata.
8890
"""
89-
return np.where(np.isnan(data), nodata_value, data)
91+
return np.where(np.isnan(data), nodata_value, data) # type: ignore
9092

9193

9294
@beartype

eis_toolkit/validation/calculate_base_metrics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from eis_toolkit.exceptions import NonMatchingCrsException, NotApplicableGeometryTypeException
1212

1313

14-
def _calculate_base_metrics( # type: ignore[no-any-unimported]
14+
def _calculate_base_metrics(
1515
raster: rasterio.io.DatasetReader,
1616
deposits: geopandas.GeoDataFrame,
1717
band: int,
@@ -71,7 +71,7 @@ def _calculate_base_metrics( # type: ignore[no-any-unimported]
7171

7272

7373
@beartype
74-
def calculate_base_metrics( # type: ignore[no-any-unimported]
74+
def calculate_base_metrics(
7575
raster: rasterio.io.DatasetReader,
7676
deposits: geopandas.GeoDataFrame,
7777
band: int = 1,

eis_toolkit/validation/get_pa_intersection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from eis_toolkit.exceptions import InvalidParameterValueException
88

99

10-
def _get_pa_intersection( # type: ignore[no-any-unimported]
10+
def _get_pa_intersection(
1111
true_positive_rate_values: np.ndarray, proportion_of_area_values: np.ndarray, threshold_values: np.ndarray
1212
) -> Point:
1313
true_positive_area_curve = LineString(np.column_stack((threshold_values, true_positive_rate_values)))

eis_toolkit/validation/plot_prediction_area_curves.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from eis_toolkit.validation.get_pa_intersection import get_pa_intersection
88

99

10-
def _plot_prediction_area_curves( # type: ignore[no-any-unimported]
10+
def _plot_prediction_area_curves(
1111
true_positive_rate_values: np.ndarray, proportion_of_area_values: np.ndarray, threshold_values: np.ndarray
1212
) -> matplotlib.figure.Figure:
1313
intersection = get_pa_intersection(true_positive_rate_values, proportion_of_area_values, threshold_values)
@@ -39,7 +39,7 @@ def _plot_prediction_area_curves( # type: ignore[no-any-unimported]
3939

4040

4141
@beartype
42-
def plot_prediction_area_curves( # type: ignore[no-any-unimported]
42+
def plot_prediction_area_curves(
4343
true_positive_rate_values: np.ndarray, proportion_of_area_values: np.ndarray, threshold_values: np.ndarray
4444
) -> matplotlib.figure.Figure:
4545
"""Plot prediction-area (P-A) plot.

eis_toolkit/validation/plot_rate_curve.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from eis_toolkit.validation.calculate_auc import calculate_auc
88

99

10-
def _plot_rate_curve( # type: ignore[no-any-unimported]
11-
x_values: np.ndarray, y_values: np.ndarray, label: str, xlab: str
12-
) -> matplotlib.figure.Figure:
10+
def _plot_rate_curve(x_values: np.ndarray, y_values: np.ndarray, label: str, xlab: str) -> matplotlib.figure.Figure:
1311
fig = plt.figure(figsize=(10, 7))
1412
plt.plot(x_values, y_values, label=label)
1513
plt.xlim(-0.01, 1)
@@ -27,7 +25,7 @@ def _plot_rate_curve( # type: ignore[no-any-unimported]
2725

2826

2927
@beartype
30-
def plot_rate_curve( # type: ignore[no-any-unimported]
28+
def plot_rate_curve(
3129
x_values: np.ndarray,
3230
y_values: np.ndarray,
3331
plot_type: str = "success_rate",

eis_toolkit/vector_processing/reproject_vector.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66

77
@beartype
8-
def reproject_vector( # type: ignore[no-any-unimported]
9-
geodataframe: geopandas.GeoDataFrame, target_crs: int
10-
) -> geopandas.GeoDataFrame:
8+
def reproject_vector(geodataframe: geopandas.GeoDataFrame, target_crs: int) -> geopandas.GeoDataFrame:
119
"""Reprojects vector data to match given coordinate reference system (EPSG).
1210
1311
Args:

mypy.ini

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ check_untyped_defs = True
33
disallow_untyped_defs = True
44
disallow_incomplete_defs = True
55
disallow_untyped_decorators = True
6-
disallow_any_unimported = True
76
warn_return_any = True
87
warn_unused_ignores = True
98
no_implicit_optional = True

0 commit comments

Comments
 (0)