markfairbanks / tidypolars

Tidy interface to polars
http://tidypolars.readthedocs.io
MIT License
321 stars 10 forks source link

```as_date``` with ```RuntimeError: please define a fmt``` #155

Closed alexandro-ag closed 2 years ago

alexandro-ag commented 2 years ago

Good afternoon,

I think I found an issue with the as_date method. In the example per the documentation, the following succeeds:

import tidypolars as tp
from tidypolars import col

date_df = tp.Tibble(date = ['2021-12-31']) # Year-Month-Day (%Y-%m-%d)
date_df.mutate(date_parsed = tp.as_date(col('date'))) # Success

However when parsing different formats (using the fmt argument), the date fails to parse:

import tidypolars as tp
from tidypolars import col

date_df = tp.Tibble(date = ['12/31/2021']) # Month/Day/Year (%m/%d/%Y)
date_df.mutate(date_parsed = tp.as_date(col('date'), fmt='%m/%d/%Y')) # RuntimeError

I also extend my appreciation for all the work on this package. I've been searching for a tidyverse implementation in python and this one knocks my expectations out of the park. Thank you.

markfairbanks commented 2 years ago

Thanks for catching this! Looks like I didn't pass the fmt arg to the underlying polars function 🤦‍♂️

Should be a quick fix.

I also extend my appreciation for all the work on this package. I've been searching for a tidyverse implementation in python and this one knocks my expectations out of the park. Thank you.

Glad to hear it's working out for you 😄

markfairbanks commented 2 years ago

All set - you'll just need to update to the latest version of tidypolars:

import tidypolars as tp
from tidypolars import col

date_df = tp.Tibble(date = ['12/31/2021'])

date_df.mutate(date_parsed = tp.as_date(col('date'), fmt='%m/%d/%Y'))
┌────────────┬─────────────┐
│ date       ┆ date_parsed │
│ ---        ┆ ---         │
│ str        ┆ date        │
╞════════════╪═════════════╡
│ 12/31/2021 ┆ 2021-12-31  │
└────────────┴─────────────┘
alexandro-ag commented 2 years ago

Works on my end! Thank for the prompt reply and response!