Skip to content

Commit

Permalink
use renamed typepigeon functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Feb 28, 2023
1 parent 2895957 commit e077818
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"requests",
"searvey >=0.2.0,<1.0",
"shapely >=1.8",
"typepigeon >=1.0.5, <2",
"typepigeon >=2.0.1",
"xarray",
]
dynamic = ["version"]
Expand Down
12 changes: 5 additions & 7 deletions stormevents/nhc/atcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def atcf_files(
)

if not isinstance(file_deck, ATCF_FileDeck):
file_deck = typepigeon.convert_value(file_deck, ATCF_FileDeck)
file_deck = typepigeon.to_type(file_deck, ATCF_FileDeck)

if not isinstance(mode, ATCF_Mode):
mode = typepigeon.convert_value(mode, ATCF_Mode)
mode = typepigeon.to_type(mode, ATCF_Mode)

if mode == ATCF_Mode.HISTORICAL and year is None or isinstance(year, Iterable):
if year is None:
Expand Down Expand Up @@ -275,15 +275,15 @@ def atcf_url(

if not isinstance(file_deck, ATCF_FileDeck):
try:
file_deck = typepigeon.convert_value(file_deck, ATCF_FileDeck)
file_deck = typepigeon.to_type(file_deck, ATCF_FileDeck)
except ValueError:
file_deck = None
if file_deck is None:
file_deck = ATCF_FileDeck.ADVISORY

if not isinstance(mode, ATCF_Mode):
try:
mode = typepigeon.convert_value(mode, ATCF_Mode)
mode = typepigeon.to_type(mode, ATCF_Mode)
except ValueError:
mode = None

Expand Down Expand Up @@ -328,9 +328,7 @@ def read_atcf(
"""

if advisories is not None:
advisories = [
typepigeon.convert_value(advisory, str) for advisory in advisories
]
advisories = [typepigeon.to_type(advisory, str) for advisory in advisories]

if isinstance(atcf, (str, PathLike, Path)):
atcf = open(atcf)
Expand Down
6 changes: 3 additions & 3 deletions stormevents/nhc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def file_deck(self) -> ATCF_FileDeck:
def file_deck(self, file_deck: ATCF_FileDeck):
if file_deck is None and self.filename is None:
if self.advisories is not None or len(self.advisories) > 0:
if ATCF_Advisory.BEST in typepigeon.convert_value(
if ATCF_Advisory.BEST in typepigeon.to_type(
self.advisories, [ATCF_Advisory]
):
file_deck = ATCF_FileDeck.BEST
Expand All @@ -377,7 +377,7 @@ def file_deck(self, file_deck: ATCF_FileDeck):
else:
file_deck = ATCF_FileDeck.BEST
elif not isinstance(file_deck, ATCF_FileDeck):
file_deck = typepigeon.convert_value(file_deck, ATCF_FileDeck)
file_deck = typepigeon.to_type(file_deck, ATCF_FileDeck)
self.__file_deck = file_deck

@property
Expand All @@ -397,7 +397,7 @@ def advisories(self, advisories: List[ATCF_Advisory]):
if advisories is None:
advisories = self.__valid_advisories
else:
advisories = typepigeon.convert_value(advisories, [str])
advisories = typepigeon.to_type(advisories, [str])
advisories = [advisory.upper() for advisory in advisories]
self.__advisories = advisories

Expand Down
14 changes: 7 additions & 7 deletions stormevents/usgs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ def usgs_flood_events(
]

if event_type is not None:
event_type = typepigeon.convert_value(event_type, [str])
event_type = typepigeon.to_type(event_type, [str])
events = events[events["event_type"].isin(event_type)]

if event_status is not None:
event_status = typepigeon.convert_value(event_status, [str])
event_status = typepigeon.to_type(event_status, [str])
events = events[events["event_status"].isin(event_status)]

if year is not None:
year = typepigeon.convert_value(year, [int])
year = typepigeon.to_type(year, [int])
events = events[events["year"].isin(year)]

return events
Expand Down Expand Up @@ -324,11 +324,11 @@ def description(self) -> str:

@property
def event_type(self) -> EventType:
return typepigeon.convert_value(self.__metadata["event_type"], EventType)
return typepigeon.to_type(self.__metadata["event_type"], EventType)

@property
def event_status(self) -> EventStatus:
return typepigeon.convert_value(self.__metadata["event_status"], EventStatus)
return typepigeon.to_type(self.__metadata["event_status"], EventStatus)

@property
def coordinator(self) -> str:
Expand All @@ -348,11 +348,11 @@ def last_updated_by(self) -> str:

@property
def start_date(self) -> datetime:
return typepigeon.convert_value(self.__metadata["start_date"], datetime)
return typepigeon.to_type(self.__metadata["start_date"], datetime)

Check warning on line 351 in stormevents/usgs/events.py

View check run for this annotation

Codecov / codecov/patch

stormevents/usgs/events.py#L351

Added line #L351 was not covered by tests

@property
def end_date(self) -> datetime:
return typepigeon.convert_value(self.__metadata["end_date"], datetime)
return typepigeon.to_type(self.__metadata["end_date"], datetime)

Check warning on line 355 in stormevents/usgs/events.py

View check run for this annotation

Codecov / codecov/patch

stormevents/usgs/events.py#L355

Added line #L355 was not covered by tests

@property
def files(self) -> DataFrame:
Expand Down
12 changes: 6 additions & 6 deletions stormevents/usgs/highwatermarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ def us_states(self) -> List[str]:

@us_states.setter
def us_states(self, us_states: List[str]):
self.__us_states = typepigeon.convert_value(us_states, [str])
self.__us_states = typepigeon.to_type(us_states, [str])

@property
def us_counties(self) -> List[str]:
return self.__us_counties

@us_counties.setter
def us_counties(self, us_counties: List[str]):
self.__us_counties = typepigeon.convert_value(us_counties, [str])
self.__us_counties = typepigeon.to_type(us_counties, [str])

@property
def hwm_type(self) -> List[HighWaterMarkType]:
Expand All @@ -152,7 +152,7 @@ def hwm_type(self) -> List[HighWaterMarkType]:
@hwm_type.setter
def hwm_type(self, hwm_type: HighWaterMarkType):
if hwm_type is not None:
self.__hwm_type = typepigeon.convert_value(hwm_type, [HighWaterMarkType])
self.__hwm_type = typepigeon.to_type(hwm_type, [HighWaterMarkType])

Check warning on line 155 in stormevents/usgs/highwatermarks.py

View check run for this annotation

Codecov / codecov/patch

stormevents/usgs/highwatermarks.py#L155

Added line #L155 was not covered by tests
else:
self.__hwm_type = None

Expand All @@ -163,7 +163,7 @@ def quality(self) -> List[HighWaterMarkQuality]:
@quality.setter
def quality(self, quality: HighWaterMarkQuality):
if quality is not None:
self.__quality = typepigeon.convert_value(quality, [HighWaterMarkQuality])
self.__quality = typepigeon.to_type(quality, [HighWaterMarkQuality])
else:
self.__quality = None

Expand All @@ -174,7 +174,7 @@ def environment(self) -> List[HighWaterMarkEnvironment]:
@environment.setter
def environment(self, environment: HighWaterMarkEnvironment):
if environment is not None:
self.__environment = typepigeon.convert_value(
self.__environment = typepigeon.to_type(

Check warning on line 177 in stormevents/usgs/highwatermarks.py

View check run for this annotation

Codecov / codecov/patch

stormevents/usgs/highwatermarks.py#L177

Added line #L177 was not covered by tests
environment, [HighWaterMarkEnvironment]
)
else:
Expand Down Expand Up @@ -204,7 +204,7 @@ def query(self) -> Dict[str, Any]:
entry.value if isinstance(entry, Enum) else entry
for entry in value
]
value = typepigeon.convert_value(value, [str])
value = typepigeon.to_type(value, [str])

if len(value) > 0:
value = ",".join(value)
Expand Down
12 changes: 6 additions & 6 deletions stormevents/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def subset_time_interval(
raise ValueError(f'cannot parse time interval "{start} - {end}"')

if not isinstance(start, datetime):
start = typepigeon.convert_value(start, datetime)
start = typepigeon.to_type(start, datetime)
if not isinstance(end, datetime):
end = typepigeon.convert_value(end, datetime)
end = typepigeon.to_type(end, datetime)

if start > end:
raise ValueError(f'given start time ("{start}") ' f'exceeds end time ("{end}")')
Expand Down Expand Up @@ -85,21 +85,21 @@ def relative_to_time_interval(
)

if not isinstance(start, datetime):
start = typepigeon.convert_value(start, datetime)
start = typepigeon.to_type(start, datetime)
if not isinstance(end, datetime):
end = typepigeon.convert_value(end, datetime)
end = typepigeon.to_type(end, datetime)

if start > end:
raise ValueError(f'given start time ("{start}") ' f'exceeds end time ("{end}")')

if isinstance(relative, timedelta) or isinstance(relative, Number):
relative = typepigeon.convert_value(relative, timedelta)
relative = typepigeon.to_type(relative, timedelta)
if relative >= timedelta(0):
relative = start + relative
else:
relative = end + relative
elif not isinstance(relative, datetime):
relative = typepigeon.convert_value(relative, datetime)
relative = typepigeon.to_type(relative, datetime)

if start <= relative <= end:
return relative
Expand Down

0 comments on commit e077818

Please sign in to comment.