Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support casting String to Time #17341

Open
2 tasks done
d-reynol opened this issue Jul 1, 2024 · 5 comments · May be fixed by #18108
Open
2 tasks done

Support casting String to Time #17341

d-reynol opened this issue Jul 1, 2024 · 5 comments · May be fixed by #18108
Labels
A-timeseries Area: date/time functionality accepted Ready for implementation enhancement New feature or an improvement of an existing feature good first issue Good for newcomers python Related to Python Polars

Comments

@d-reynol
Copy link

d-reynol commented Jul 1, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import datetime as dt
import polars as pl
# This works and produces the expected output
pl.Series([dt.date(2023, 12, 31)]).cast(pl.String).cast(pl.Date)
shape: (1,)
Series: '' [date]
[
	2023-12-31
]
# This errors
pl.Series([dt.time(12, 14, 9)]).cast(pl.String).cast(pl.Time)
polars.exceptions.InvalidOperationError: conversion from `str` to `time` failed in column '' for 1 out of 1 values: ["12:14:09"]

Log output

No response

Issue description

I can cast strings to dates, but not to times.

Using .str.to_time() works, but the current behavior should (ideally) be consistent

Expected behavior

Should be able to cast strings to times

Installed versions

--------Version info---------
Polars:               1.0.0
Index type:           UInt32
Platform:             Windows-10-10.0.19045-SP0
Python:               3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.2
pyarrow:              <not installed>
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@d-reynol d-reynol added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jul 1, 2024
@stinodego stinodego added the A-timeseries Area: date/time functionality label Jul 2, 2024
@stinodego
Copy link
Member

Agree we should support casting String to Time. This is not a bug though, it's simply not supported yet. I'll rebrand this as a feature request and accept it.

@stinodego stinodego added enhancement New feature or an improvement of an existing feature accepted Ready for implementation and removed bug Something isn't working needs triage Awaiting prioritization by a maintainer labels Jul 2, 2024
@stinodego stinodego changed the title Inconsistency when casting string to time vs sting to date Support casting String to Time Jul 2, 2024
@stinodego stinodego added the good first issue Good for newcomers label Jul 2, 2024
@d-reynol
Copy link
Author

d-reynol commented Jul 2, 2024

thank you!

@Biswas-N
Copy link

Biswas-N commented Jul 2, 2024

Can I take up this task?

@stinodego
Copy link
Member

Can I take up this task?

Sure! Take a look at how casting is implemented for String to Date, that should give you a good starting point.

@ntn-nicholas
Copy link

Has there been any progress/findings on this issue? I'm interested in also contributing on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-timeseries Area: date/time functionality accepted Ready for implementation enhancement New feature or an improvement of an existing feature good first issue Good for newcomers python Related to Python Polars
Projects
Status: Ready
Development

Successfully merging a pull request may close this issue.

4 participants