Skip to content

Commit

Permalink
Merge pull request #156 from markfairbanks/date-fmt
Browse files Browse the repository at this point in the history
Pass `fmt` arg in `as_date`/`as_datetime`
  • Loading branch information
markfairbanks committed Dec 8, 2021
2 parents 2ff5ab5 + e382402 commit bba6aa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## v0.2.8 (in development)
## v0.2.8 (2021/12/08)

#### Bug fixes
* Can use `fmt` arg in `as_date()` and `as_datetime()` (#155)

## v0.2.7 (2021/11/19)

Expand Down
8 changes: 7 additions & 1 deletion tests/test_lubridate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ def test_date():
year = col('date').dt.year()
)
)
assert actual.frame_equal(expected), "date operations failed"
assert actual.frame_equal(expected), "date operations failed"

def as_date_fmt():
"""Can pass fmt to as_date"""
df = tp.Tibble(date = ['12/31/2021'])
out = df.mutate(date_parsed = tp.as_date(col('date'), fmt='%m/%d/%Y'))
assert out.pull().is_datetime(), "as_date fmt failed"
4 changes: 2 additions & 2 deletions tidypolars/lubridate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def as_date(x, fmt = None):
>>> df.mutate(date_x = tp.as_date(col('x')))
"""
x = _col_expr(x)
return x.str.strptime(pl.Date)
return x.str.strptime(pl.Date, fmt = fmt)

def as_datetime(x, fmt = None):
"""
Expand All @@ -53,7 +53,7 @@ def as_datetime(x, fmt = None):
>>> df.mutate(date_x = tp.as_datetime(col('x')))
"""
x = _col_expr(x)
return x.str.strptime(pl.Datetime)
return x.str.strptime(pl.Datetime, fmt = fmt)

def hour(x):
"""
Expand Down

0 comments on commit bba6aa6

Please sign in to comment.