Skip to content

Commit

Permalink
fix: Fix type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
jsakv committed Jul 9, 2024
1 parent 84bc6fe commit f6eb65f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Empty file.
7 changes: 3 additions & 4 deletions pyrorisks/utils/fwi_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import rasterio
from rasterio.features import shapes
import geopandas as gpd
import requests
from io import BytesIO
import json
from typing import Optional
from typing import Optional, Dict, Any


class FWIHelpers:
Expand Down Expand Up @@ -41,7 +40,7 @@ def get_fwi(self, tiff_url: str) -> Optional[gpd.GeoDataFrame]:
image = src.read(1) # first band
results = (
{"properties": {"fwi_pixel_value": v}, "geometry": s}
for i, (s, v) in enumerate(shapes(image, mask=mask, transform=data["transform"]))
for i, (s, v) in enumerate(rasterio.features.shapes(image, mask=mask, transform=data["transform"]))
)

geoms = list(results)
Expand Down Expand Up @@ -96,7 +95,7 @@ def fwi_category(self, fwi_pixel_val: int) -> int:

return 3

def fwi_geojson_maker(self, geodataframe: gpd.GeoDataFrame) -> json:
def fwi_geojson_maker(self, geodataframe: gpd.GeoDataFrame) -> Dict[str, Any]:
"""
Converts a GeoDataFrame into a GeoJSON.
Expand Down
9 changes: 5 additions & 4 deletions pyrorisks/utils/s3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import boto3
import json
from typing import Dict, Any, Optional

import os

Expand All @@ -13,7 +14,7 @@ class S3Bucket:
Example:
To create an instance of the S3Bucket class with a session, use:
>>> from pyro_risks.utils.s3 import S3Bucket
>>> from pyrorisks.utils.s3 import S3Bucket
>>> s3 = S3Bucket(
bucket_name='mybucket',
Expand Down Expand Up @@ -97,7 +98,7 @@ def upload_file(self, file_path: str, object_key: str) -> None:
"""
self.bucket.upload_file(file_path, object_key)

def write_json_to_s3(self, json_data: json, object_key: str) -> None:
def write_json_to_s3(self, json_data: Dict[str, Any], object_key: str) -> None:
"""
Writes a JSON file on the S3 bucket.
Expand Down Expand Up @@ -176,7 +177,7 @@ def list_folders(self, prefix: str = "", delimiter: str = "") -> list[str]:

def list_files(
self,
patterns: list[str] = None,
patterns: Optional[list[str]] = None,
prefix: str = "",
delimiter: str = "",
limit: int = 0,
Expand All @@ -198,7 +199,7 @@ def list_files(
if limit != 0:
object_filter = object_filter.limit(limit)
for obj in object_filter:
if not patterns or (type(patterns) == list and any([p in obj.key for p in patterns])):
if not patterns or (isinstance(patterns, list) and any([p in obj.key for p in patterns])):
files.append(obj.key)
return files

Expand Down

0 comments on commit f6eb65f

Please sign in to comment.