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

Add dt.replace functions to specify specific day, month, year, etc. for date and datetime #15794

Closed
mcrumiller opened this issue Apr 19, 2024 · 2 comments
Labels
enhancement New feature or an improvement of an existing feature

Comments

@mcrumiller
Copy link
Contributor

mcrumiller commented Apr 19, 2024

Description

The native datetime has .replace functions that allow the user to change the day, month, year, etc. to specific values:

import datetime
datetime.date(2024, 1, 1).replace(month=3, day=5)
# datetime.date(2024, 3, 5)

This would be useful for our Date and Datetime dtypes as well:

from datetime import date
import polars as pl

s = pl.Series([date(2024, 1, 31), date(2024, 5, 30)])
s.dt.replace(day=10)
# shape: (2,)
# Series: '' [date]
# [
#         2024-01-10
#         2024-05-10
# ]

This can currently be achieved via s.dt.truncate("1mo").dt.offset_by("9d") but it's a bit ugly.

@mcrumiller mcrumiller added the enhancement New feature or an improvement of an existing feature label Apr 19, 2024
@MarcoGorelli
Copy link
Collaborator

MarcoGorelli commented Apr 20, 2024

I think this is a duplicate of your own issue 😉 #8879
closing in favour of that one then

@MarcoGorelli MarcoGorelli closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2024
@mcrumiller
Copy link
Contributor Author

Heh, sorry Marco, good find. 🤭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants