Skip to content

Commit

Permalink
update util_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
xyluo25 committed Oct 29, 2024
1 parent 5244028 commit 3dcb0a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
9 changes: 4 additions & 5 deletions pyufunc/util_datetime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
# Author/Copyright: Mr. Xiangyong Luo
##############################################################

from ._dt_format import (
fmt_dt_to_str,
fmt_str_to_dt)
from ._dt_format import (fmt_dt_to_str,
fmt_str_to_dt)
from ._dt_timezone import (list_all_timezones,
get_timezone,
cvt_dt_to_tz)
cvt_current_dt_to_tz)
from ._dt_time_difference import get_time_diff_in_unit
from ._dt_group import (group_dt_yearly,
group_dt_monthly,
Expand All @@ -27,7 +26,7 @@
# _dt_timezone
"list_all_timezones",
"get_timezone",
"cvt_dt_to_tz",
"cvt_current_dt_to_tz",

# _dt_time_difference
"get_time_diff_in_unit",
Expand Down
10 changes: 3 additions & 7 deletions pyufunc/util_datetime/_dt_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ def fmt_dt_to_str(dt: Union[datetime.datetime, str] = "",
>>> from pyufunc import fmt_dt_to_str
>>> fmt_dt_to_str()
'2024-02-06'
>>> fmt_dt_to_str(df_fmt="%Y/%m/%d %H:%M:%S")
>>> fmt_dt_to_str(dt_fmt="%Y/%m/%d %H:%M:%S")
'2024/02/06 00:00:00'
>>> fmt_dt_to_str("2024-02-06", df_fmt="%Y/%m/%d")
>>> fmt_dt_to_str("2024-02-06", dt_fmt="%Y/%m/%d")
'2024/02/06'
>>> fmt_dt_to_str("2024-02-06", df_fmt="%Y/%m/%d %H:%M:%S")
>>> fmt_dt_to_str("2024-02-06", dt_fmt="%Y/%m/%d %H:%M:%S")
'2024/02/06 00:00:00'
>>> fmt_dt_to_str(datetime.datetime.now(), "%Y/%m/%d %H:%M:%S")
'2024/02/06 11:11:11'
"""
Expand Down
4 changes: 3 additions & 1 deletion pyufunc/util_datetime/_dt_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def group_dt_weekly(df: pd.DataFrame, interval: int = 1, col: list = ["datetime"
dataframe["datetime"] = pd.to_datetime(dataframe["datetime"])
df_res = dataframe.groupby(pd.Grouper(key="datetime",
axis=0,
freq="%sW" % interval)).agg(["count", "mean", "sum"])
freq=f"{interval}W")).agg(["count",
"mean",
"sum"])
df_res.reset_index(inplace=True)
df_res.columns = [i[0] if i[0] == "datetime" else i[1]
for i in list(df_res.columns)]
Expand Down
2 changes: 1 addition & 1 deletion pyufunc/util_datetime/_dt_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_timezone() -> str:


# convert current datetime to another timezone datetime
def cvt_dt_to_tz(dt: datetime = datetime.datetime.now(),
def cvt_current_dt_to_tz(dt: datetime = datetime.datetime.now(),
timezone: str = "UTC") -> datetime:
"""Convert datetime to another timezone datetime
Expand Down

0 comments on commit 3dcb0a7

Please sign in to comment.