Open dridk opened 11 months ago
thanks for the request - I'm tempted to say this is too specialised and would be better suited to a polars plugin, but curious what others think
Is this equivalent to a fixed integer offset? If so, yes, I'd say this is a little beyond what should be available as core functionality.
I think this could actually be quite useful for some domains where it is a typical representation (and also perhaps areas like sqlite/excel interop, which both use Julians natively). It's also easy/lightweight to implement; in fact I'm 80% done with it after half a coffee π
β
Update: I take it back; it's trivial to implement naΓ―vely, but if you dig in deeper there are issues relating to floating point deviation that can bite you in the π if you're not careful; at one point I found myself looking through source code used at NASA and figured I'd sit on this one for a bit π€£
I've added this to polars-xdt
In [2]: from datetime import datetime
...: import polars_xdt # noqa: F401
...: df = pl.DataFrame(
...: {
...: "date_col": [
...: datetime(2013, 1, 1, 0, 30),
...: datetime(2024, 1, 7, 13, 18, 51),
...: ],
...: }
...: )
...: with pl.Config(float_precision=10) as cfg:
...: print(df.with_columns(
...: julian_date=pl.col("date_col").xdt.to_julian_date()
...: ))
...:
shape: (2, 2)
βββββββββββββββββββββββ¬βββββββββββββββββββββ
β date_col β julian_date β
β --- β --- β
β datetime[ΞΌs] β f64 β
βββββββββββββββββββββββͺβββββββββββββββββββββ‘
β 2013-01-01 00:30:00 β 2456293.5208333335 β
β 2024-01-07 13:18:51 β 2460317.0547569445 β
βββββββββββββββββββββββ΄βββββββββββββββββββββ
OK to close this and for people to use that, or does it need to be in the core library?
OK to close this and for people to use that, or does it need to be in the core library?
@MarcoGorelli: Probably worth having (I was eyeing it for polars-sql
functionality just recently, and with SQLite/Excel both using Julians there might be some other benefits). Will have to take a look at what algorithm you used; the industrial-strength version has various tricks to guard against floating point rounding deviations creeping in :))
sounds good, thanks! here it is:
Description
Could you add Julian parser like pandas ? https://pandas.pydata.org/docs/reference/api/pandas.Timestamp.to_julian_date.html