Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
fixed type import issues across modules
Browse files Browse the repository at this point in the history
  • Loading branch information
seekinginfiniteloop committed Dec 26, 2023
1 parent 7821df1 commit eb99d37
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 187 deletions.
6 changes: 3 additions & 3 deletions fedcal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
`to_fedstamp` and `to_fedindex`. This makes them easy to import and use, like:
```python
from fedcal import to_fedindex
dates = ((1999,10,1), (2040,9,30))
index = to_fedindex(dates)
import fedcal as fc
dates = (1999,10,1), (2040,9,30)
fdx = fc.to_fedindex(dates)
```
We also import the `FedDepartment` class and the `Dept` enum, which are used
Expand Down
6 changes: 2 additions & 4 deletions fedcal/_civpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
`FedPayDay` calculates and provides federal civilian biweekly paydays
and outputs them in a variety of formats.
"""
from typing import TYPE_CHECKING
from __future__ import annotations

import pandas as pd
from attrs import define, field
from pandas import DatetimeIndex, Series, Timestamp

from fedcal import constants, time_utils

if TYPE_CHECKING:
from pandas import DatetimeIndex, Series, Timestamp


@define(order=True)
class FedPayDay:
Expand Down
11 changes: 4 additions & 7 deletions fedcal/_cls_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@
(i.e. FedIndex); which interferes with the wrapper and we probably need to
rethink the approach.
"""
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Any

import numpy as np
import pandas as pd
from attr import define, field
from funcy import decorator
from numpy.typing import NDArray
from pandas import DatetimeIndex, Series

from fedcal._meta import MagicDelegator

if TYPE_CHECKING:
from typing import Any

from numpy.typing import NDArray
from pandas import DatetimeIndex, Series


class NPArrayImposter(
metaclass=MagicDelegator, delegate_to="array", delegate_class=np.ndarray
Expand Down
11 changes: 4 additions & 7 deletions fedcal/_date_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@
- holidays (`FedHolidays`)
- fiscal years/quarters (`FedFiscalCal`)
"""
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING
from typing import ClassVar, Generator

import pandas as pd
from attrs import define, field
from numpy.typing import NDArray
from pandas import DatetimeIndex, Index, PeriodIndex, Series, Timestamp
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay

from fedcal import constants
from fedcal.time_utils import ensure_datetimeindex

if TYPE_CHECKING:
from typing import ClassVar, Generator

from numpy.typing import NDArray
from pandas import DatetimeIndex, Index, PeriodIndex, Series, Timestamp


@define(order=True, auto_attribs=True)
class FedBusDay:
Expand Down
33 changes: 19 additions & 14 deletions fedcal/_dept_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,33 @@
- `DepartmentState` queries and retrieves points and ranges
of interval data from `_tree.Tree()`
"""
from __future__ import annotations

from itertools import product
from typing import TYPE_CHECKING
from typing import ClassVar

from attrs import define
from intervaltree import IntervalTree
from pandas import Timestamp

from fedcal import time_utils
from fedcal._tree import Tree
from fedcal.constants import (CR_DATA_CUTOFF_DATE, DEPTS_SET, DHS_FORMED,
STATUS_MAP, Dept)
from fedcal._typing import (
StatusDictType,
StatusGeneratorType,
StatusMapType,
StatusPoolType,
StatusTupleType,
)
from fedcal.constants import (
CR_DATA_CUTOFF_DATE,
DEPTS_SET,
DHS_FORMED,
STATUS_MAP,
Dept,
)
from fedcal.depts import FedDepartment

if TYPE_CHECKING:
from typing import ClassVar

from intervaltree import IntervalTree
from pandas import Timestamp

from fedcal._typing import (StatusDictType, StatusGeneratorType,
StatusMapType, StatusPoolType, StatusTupleType)

@define(order=True, auto_attribs=True)
class DepartmentStatus:
Expand Down Expand Up @@ -305,9 +312,7 @@ def get_state(cls, date: Timestamp) -> StatusDictType:
"""
status_pool: StatusPoolType = DepartmentStatus.get_status_pool()
tree: IntervalTree = (
cls.tree if cls.tree is not None else cls.get_state_tree()
)
tree: IntervalTree = cls.tree if cls.tree is not None else cls.get_state_tree()
status_map: "StatusMapType" = STATUS_MAP

posix_date: int = time_utils.pdtimestamp_to_posix_day(timestamp=date)
Expand Down
10 changes: 4 additions & 6 deletions fedcal/_mil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
- `ProbableMilitaryPassday` heuristically calculates probable
military passdays surrounding federal holidays.
"""
from typing import TYPE_CHECKING
from __future__ import annotations

import pandas as pd
from attrs import define, field
from numpy.typing import NDArray
from pandas import DataFrame, DatetimeIndex, Series, Timestamp

from fedcal import _date_attributes, time_utils

if TYPE_CHECKING:
from numpy.typing import NDArray
from pandas import DataFrame, DatetimeIndex, Series, Timestamp


@define(order=True, kw_only=True)
class MilitaryPayDay:
Expand Down Expand Up @@ -168,7 +166,7 @@ class ProbableMilitaryPassDay:
DataFrame of boolean masks for identifying passdays.
"""

dates: DatetimeIndex | Series | Timestamp | None = field(default=None)
dates: DatetimeIndex | Series[Timestamp] | Timestamp | None = field(default=None)

passdays: NDArray[bool] | None = field(default=None, init=False)

Expand Down
32 changes: 19 additions & 13 deletions fedcal/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,31 @@ class -- we only want (and need) to build one. As designed,
`CRTreeGrower` and `AppropriationsTreeGrower` are initialized by `Tree`,
and so are also effectively singletons.
"""
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Any, ClassVar, Tuple

from attrs import define, field
from intervaltree import IntervalTree
from pandas import Timestamp

from fedcal import time_utils
from fedcal.constants import (APPROPRIATIONS_GAPS, CR_DEPARTMENTS, DEPTS_SET,
DHS_FORMED, STATUS_MAP, Dept, ShutdownFlag)

if TYPE_CHECKING:
from typing import Any, ClassVar, Tuple

from pandas import Timestamp

from fedcal._typing import (AppropriationsGapsMapType,
AssembledBudgetIntervalType, CRMapType,
FedStampConvertibleTypes)
from fedcal.time_utils import YearMonthDay
from fedcal._typing import (
AppropriationsGapsMapType,
AssembledBudgetIntervalType,
CRMapType,
FedStampConvertibleTypes,
)
from fedcal.constants import (
APPROPRIATIONS_GAPS,
CR_DEPARTMENTS,
DEPTS_SET,
DHS_FORMED,
STATUS_MAP,
Dept,
ShutdownFlag,
)
from fedcal.time_utils import YearMonthDay


def _get_date_interval(
Expand Down
51 changes: 25 additions & 26 deletions fedcal/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@
This module provides internal type definitions for fedcal to keep the code
clean but well-typed.
"""
from __future__ import annotations

from typing import TYPE_CHECKING
import datetime
from typing import TYPE_CHECKING, Generator, Mapping, Union

if TYPE_CHECKING:
import datetime
from typing import Generator, Mapping, Union

import numpy as np
import pandas as pd
from bidict import frozenbidict
from numpy.typing import NDArray
from bidict import frozenbidict
from numpy import datetime64, int64
from numpy.typing import NDArray
from pandas import DatetimeIndex, Index, PeriodIndex, Series, Timestamp

if TYPE_CHECKING:
from fedcal.constants import AppropsStatus, Dept, OpsStatus, ShutdownFlag
from fedcal.depts import FedDepartment
from fedcal.time_utils import YearMonthDay

FedStampConvertibleTypes = Union[
pd.Timestamp,
Timestamp,
int,
np.int64,
np.datetime64,
int64,
datetime64,
float,
YearMonthDay,
"YearMonthDay",
tuple[int, int, int],
tuple[str, str, str],
str,
Expand All @@ -47,34 +46,34 @@

FedIndexConvertibleTypes = Union[
tuple[FedStampConvertibleTypes, FedStampConvertibleTypes],
tuple[pd.Timestamp, pd.Timestamp],
tuple[Timestamp, Timestamp],
NDArray,
pd.Series,
pd.DatetimeIndex,
pd.Index,
pd.PeriodIndex,
Series,
DatetimeIndex,
Index,
PeriodIndex,
]

AppropriationsGapsMapType = Mapping[tuple[int, int], tuple[set[Dept], ShutdownFlag]]
AppropriationsGapsMapType = Mapping[tuple[int, int], tuple[set["Dept"], "ShutdownFlag"]]

CRMapType = Mapping[tuple[int, int], set[Dept]]
CRMapType = Mapping[tuple[int, int], set["Dept"]]

StatusTupleType = tuple[AppropsStatus, OpsStatus]
StatusTupleType = tuple["AppropsStatus", "OpsStatus"]

AssembledBudgetIntervalType = tuple[set[Dept], StatusTupleType]
AssembledBudgetIntervalType = tuple[set["Dept"], StatusTupleType]

DateStampStatusMapType = Mapping[Dept, StatusTupleType]
DateStampStatusMapType = Mapping["Dept", StatusTupleType]

StatusMapType = frozenbidict[str, StatusTupleType]

StatusPoolType = Mapping[tuple[Dept, str], FedDepartment]
StatusPoolType = Mapping[tuple["Dept", str], "FedDepartment"]

StatusDictType = dict[Dept, FedDepartment]
StatusDictType = dict["Dept", "FedDepartment"]

StatusGeneratorType = Generator[tuple[str, StatusDictType], None, None]

StatusCacheType = dict[str, StatusDictType]

ExtractedStatusDataGeneratorType = Generator[
tuple[pd.Timestamp, FedDepartment], None, None
tuple[Timestamp, "FedDepartment"], None, None
]
21 changes: 9 additions & 12 deletions fedcal/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,21 @@
The data are entirely within the public domain. I was unable to find a
publicly available dataset with this information precompiled; so I made one.
"""
from __future__ import annotations

from enum import Enum, unique
from typing import TYPE_CHECKING
from typing import Any, Generator, Literal, Self

import pandas as pd
from bidict import frozenbidict
from pandas import Timestamp

if TYPE_CHECKING:
from typing import Any, Generator, Literal, Self

from pandas import Timestamp

from ._typing import (
AppropriationsGapsMapType,
CRMapType,
StatusMapType,
StatusTupleType,
)
from fedcal._typing import (
AppropriationsGapsMapType,
CRMapType,
StatusMapType,
StatusTupleType,
)


@unique
Expand Down
12 changes: 4 additions & 8 deletions fedcal/depts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@
from those queries, and can use `FedDepartment`'s properties to customize
that output.
"""
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Any, Generator, Tuple

from attrs import astuple, field, frozen

from fedcal.constants import READABLE_STATUS_MAP

if TYPE_CHECKING:
from typing import Any, Generator, Tuple

from ._typing import StatusDictType, StatusTupleType
from .constants import AppropsStatus, Dept, OpsStatus
from fedcal._typing import StatusDictType, StatusTupleType
from fedcal.constants import READABLE_STATUS_MAP, AppropsStatus, Dept, OpsStatus


@frozen()
Expand Down
Loading

0 comments on commit eb99d37

Please sign in to comment.