diff --git a/fedcal/__init__.py b/fedcal/__init__.py index dcb5d6a..da67c2c 100644 --- a/fedcal/__init__.py +++ b/fedcal/__init__.py @@ -38,7 +38,6 @@ MilitaryPayDay, ) from .utils import ( - YearMonthDay, dt64_to_date, dt64_to_dow, iso_to_ts, @@ -46,6 +45,7 @@ to_dt64, to_timestamp, ) +from .status import GovStatus __all__: list[str] = [ "Dept", @@ -57,11 +57,11 @@ "FedIndex", "FedPayDay", "FedStamp", + "GovStatus", "MagicDelegator", "MilitaryPassDay", "MilitaryPayDay", "Month", - "YearMonthDay", "dt64_to_date", "dt64_to_dow", "iso_to_ts", diff --git a/fedcal/_typing.py b/fedcal/_typing.py index 49cff53..18e44c8 100644 --- a/fedcal/_typing.py +++ b/fedcal/_typing.py @@ -25,7 +25,6 @@ from pandas import DatetimeIndex, Index, Interval, PeriodIndex, Series, Timestamp if TYPE_CHECKING: - from fedcal.utils import YearMonthDay from fedcal.enum import EnumBase TimestampSeries = "Series[Timestamp]" @@ -38,7 +37,6 @@ int64, datetime64, float, - "YearMonthDay", tuple[int, int, int], tuple[str, str, str], str, diff --git a/fedcal/fedindex.py b/fedcal/fedindex.py index 0044751..b52d025 100644 --- a/fedcal/fedindex.py +++ b/fedcal/fedindex.py @@ -47,7 +47,6 @@ MilitaryPassDay, MilitaryPayDay, ) -from fedcal.utils import YearMonthDay class FedIndex( @@ -298,10 +297,7 @@ def _set_default_index() -> DatetimeIndex: ------- `pd.DatetimeIndex` with default range of FY99 to FY44. """ - default_range: tuple["YearMonthDay", "YearMonthDay"] = ( - utils.YearMonthDay(year=1998, month=10, day=1), - utils.YearMonthDay(year=2045, month=9, day=30), - ) + default_range: tuple[Timestamp, Timestamp] = pd.Timestamp(year=1998,month=10,day=1), pd.Timestamp(year=2045,month=9,day=30) return utils.to_datetimeindex(default_range) def set_self_date_range(self) -> tuple[Timestamp, Timestamp]: @@ -707,6 +703,9 @@ def departments_bool(self) -> DataFrame: pass + @staticmethod + def get_status_keys() -> + def to_fedindex(*dates: FedIndexConvertibleTypes) -> FedIndex: """ diff --git a/fedcal/fedstamp.py b/fedcal/fedstamp.py index 10ae3be..e324a96 100644 --- a/fedcal/fedstamp.py +++ b/fedcal/fedstamp.py @@ -36,7 +36,7 @@ MilitaryPassDay, MilitaryPayDay, ) -from fedcal.utils import YearMonthDay, to_timestamp, ts_to_posix_day +from fedcal.utils import to_timestamp, ts_to_posix_day class FedStamp(metaclass=MagicDelegator, delegate_to="ts", delegate_class=pd.Timestamp): @@ -66,9 +66,6 @@ class FedStamp(metaclass=MagicDelegator, delegate_to="ts", delegate_class=pd.Tim _fiscalcal: A *private* lazy attribute that caches our FiscalCalendar instance once called. - year_month_day - returns the FedStamp as a YearMonthDay object. - posix_day Returns the POSIX-day timestamp normalized to midnight. @@ -311,23 +308,6 @@ def __getattribute__(self, name: str) -> Any: # static utility methods # utility properties - @property - def year_month_day(self) -> "YearMonthDay": - """ - Returns a YearMonthDay object for the date. - - Returns - ------- - A YearMonthDay object representing the year, month, and day of the - ts. - - """ - return YearMonthDay( - year=self.ts.year, - month=self.ts.month, - day=self.ts.day, - ) - @property def posix_day(self) -> int: """ diff --git a/fedcal/utils.py b/fedcal/utils.py index 86262b3..3363a73 100644 --- a/fedcal/utils.py +++ b/fedcal/utils.py @@ -39,10 +39,6 @@ dow using numpy vectorized operations. Primarily used for custom DateOffset object calculations. -- `YearMonthDay` a class for handling date conversions from year, month, day. -It's there because I wanted something cleaner than datetime. I like it. It's -gonna stay. - - `to_timestamp` and `to_datetimeindex` are singledispatch converter functions for converting a wide range of possible time inputs to `pd.Timestamp` and `pd.DatetimeIndex` respectively. As they can look complex for the uninitiated @@ -355,124 +351,6 @@ def dt64_to_dow(dtarr: NDArray[datetime64]) -> NDArray[datetime64 | int64]: return out -@dataclass(order=True, slots=True) -class YearMonthDay: - - """ - A class to handle conversion of year,month,day integer input to other date - types needed by the calendar. - - Do we *need* YearMonthDay? No, but it does provide clear typing and ensure - smooth functioning for the most common form of programmatic date input - (i.e. year, month, day). We need it in the same sense that an - average person needs a remote controlled drone... they don't, but it beats - climbing on a roof. Doesn't YearMonthDay look so much nicer in a type - hint than tuple[int, int, int]? I think so. Could we use Python date - instead? Also yes. - - Attributes - ---------- - year : Four digit year as an integer - month : integer month - day : integer day - - Methods - ------- - from_timestamp(date: Timestamp) -> YearMonthDay - Convert a pandas pd.Timestamp object into a YearMonthDay - object. - - to_posix_timestamp(self) -> int - Converts a YearMonthDay object to a POSIX-day integer timestamp. - - to_ts(self) -> Timestamp - Converts YearMonthDay to pandas pd.Timestamp. - - to_pydate(self) -> date - Converts YearMonthDay to Python date object (datetime.date) - - timetuple(self) -> tuple[int, int, int] - Returns a tuple of YearMonthDay attributes. - - """ - - year: int = field(converter=int) - month: int = field(converter=int) - day: int = field(converter=int) - - @staticmethod - def from_timestamp(date: Timestamp) -> Self: - """ - Convert a pandas pd.Timestamp object into a - YearMonthDay object. - - Parameters - ---------- - date : Date to convert - - Returns - ------- - YearMonthDay object - - """ - return YearMonthDay(year=date.year, month=date.month, day=date.day) - - def to_timestamp(self) -> int: - """ - Converts a YearMonthDay object to a POSIX-day integer timestamp. - - Returns - ------- - A POSIX timestamp as an integer (seconds since the Unix Epoch). - """ - return int(self.to_ts().timestamp()) - - def to_timestamp_day(self) -> int: - """ - Converts a YearMonthDay object to a POSIX-day integer timestamp. - - Returns - ------- - A POSIX-day timestamp as an integer (whole days since the Unix Epoch). - - """ - return ts_to_posix_day(timestamp=self.to_ts()) - - def to_ts(self) -> Timestamp: - """ - Converts YearMonthDay to pandas pd.Timestamp. - - Returns - ------- - A pandas pd.Timestamp object. - - """ - return pd.Timestamp(year=self.year, month=self.month, day=self.day) - - def to_pydate(self) -> datetime.date: - """ - Converts YearMonthDay to Python datetime.date. - - Returns - ------- - A Python datetime.date object. - - """ - return datetime.date(year=self.year, month=self.month, day=self.day) - - @property - def timetuple(self) -> tuple[int, int, int]: - """ - Returns a tuple of YearMonthDay attributes. - - Returns - ------- - A tuple of YearMonthDay attributes. - - """ - return self.year, self.month, self.day - - @singledispatch def to_timestamp(date_input: FedStampConvertibleTypes) -> Timestamp | None: """ @@ -576,12 +454,6 @@ def _date_to_timestamp( return _normalize_timestamp(date_input) -@to_timestamp.register(cls=YearMonthDay) -def _yearmonthday_to_timestamp(date_input: YearMonthDay) -> Timestamp: - """Conversion for YearMonthDay objects.""" - return _normalize_timestamp(date_input.to_ts()) - - @to_timestamp.register(cls=tuple) def _timetuple_to_timestamp(date_input: tuple) -> Timestamp: if len(date_input) != 3: @@ -600,7 +472,7 @@ def _timetuple_to_timestamp(date_input: tuple) -> Timestamp: if not 1970 <= year <= 2200: raise ValueError("Year must be a four-digit number between 1970 and 2199") - return _normalize_timestamp(YearMonthDay(year=year, month=month, day=day).to_ts()) + return _normalize_timestamp(pd.Timestamp(year=year, month=month, day=day)) def _check_year(dates: Timestamp | DatetimeIndex) -> Timestamp | DatetimeIndex: @@ -852,7 +724,6 @@ def _normalize_datetimeindex(datetimeindex: DatetimeIndex) -> DatetimeIndex: __all__: list[str] = [ - "YearMonthDay", "check_timestamp", "datetime_keys", "dt64_to_date",