Class: Polars::DateTimeNameSpace
- Inherits:
-
Object
- Object
- Polars::DateTimeNameSpace
- Defined in:
- lib/polars/date_time_name_space.rb
Overview
Series.dt namespace.
Instance Method Summary collapse
-
#[](item) ⇒ Object
Get item.
-
#cast_time_unit(tu) ⇒ Series
Cast the underlying data to another time unit.
-
#cast_time_zone(tz) ⇒ Series
Cast time zone for a Series of type Datetime.
-
#day ⇒ Series
Extract the day from the underlying date representation.
-
#days ⇒ Series
Extract the days from a Duration type.
-
#epoch(tu = "us") ⇒ Series
Get the time passed since the Unix EPOCH in the give time unit.
-
#hour ⇒ Series
Extract the hour from the underlying DateTime representation.
-
#hours ⇒ Series
Extract the hours from a Duration type.
-
#iso_year ⇒ Series
Extract ISO year from underlying Date representation.
-
#max ⇒ Object
Return maximum as Ruby object.
-
#mean ⇒ Object
Return mean as Ruby object.
-
#median ⇒ Object
Return median as Ruby object.
-
#microsecond ⇒ Series
Extract the microseconds from the underlying DateTime representation.
-
#microseconds ⇒ Series
Extract the microseconds from a Duration type.
-
#millisecond ⇒ Series
Extract the milliseconds from the underlying DateTime representation.
-
#milliseconds ⇒ Series
Extract the milliseconds from a Duration type.
-
#min ⇒ Object
Return minimum as Ruby object.
-
#minute ⇒ Series
Extract the minutes from the underlying DateTime representation.
-
#minutes ⇒ Series
Extract the minutes from a Duration type.
-
#month ⇒ Series
Extract the month from the underlying date representation.
-
#nanosecond ⇒ Series
Extract the nanoseconds from the underlying DateTime representation.
-
#nanoseconds ⇒ Series
Extract the nanoseconds from a Duration type.
-
#offset_by(by) ⇒ Series
Offset this date by a relative time offset.
-
#ordinal_day ⇒ Series
Extract ordinal day from underlying date representation.
-
#quarter ⇒ Series
Extract quarter from underlying Date representation.
-
#round(every, offset: nil) ⇒ Series
Divide the date/ datetime range into buckets.
-
#second(fractional: false) ⇒ Series
Extract seconds from underlying DateTime representation.
-
#seconds ⇒ Series
Extract the seconds from a Duration type.
-
#strftime(fmt) ⇒ Series
Format Date/datetime with a formatting rule.
-
#timestamp(tu = "us") ⇒ Series
Return a timestamp in the given time unit.
-
#truncate(every, offset: nil) ⇒ Series
Divide the date/ datetime range into buckets.
-
#tz_localize(tz) ⇒ Series
Localize tz-naive Datetime Series to tz-aware Datetime Series.
-
#week ⇒ Series
Extract the week from the underlying date representation.
-
#weekday ⇒ Series
Extract the week day from the underlying date representation.
-
#with_time_unit(tu) ⇒ Series
Set time unit a Series of dtype Datetime or Duration.
-
#with_time_zone(tz) ⇒ Series
Set time zone a Series of type Datetime.
-
#year ⇒ Series
Extract the year from the underlying date representation.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Polars::ExprDispatch
Instance Method Details
#[](item) ⇒ Object
Get item.
16 17 18 19 |
# File 'lib/polars/date_time_name_space.rb', line 16 def [](item) s = Utils.wrap_s(_s) s[item] end |
#cast_time_unit(tu) ⇒ Series
Cast the underlying data to another time unit. This may lose precision.
876 877 878 |
# File 'lib/polars/date_time_name_space.rb', line 876 def cast_time_unit(tu) super end |
#cast_time_zone(tz) ⇒ Series
Cast time zone for a Series of type Datetime.
Different from with_time_zone
, this will also modify
the underlying timestamp.
991 992 993 |
# File 'lib/polars/date_time_name_space.rb', line 991 def cast_time_zone(tz) super end |
#day ⇒ Series
Extract the day from the underlying date representation.
Applies to Date and Datetime columns.
Returns the day of month starting from 1. The return value ranges from 1 to 31. (The last day of month differs by months.)
395 396 397 |
# File 'lib/polars/date_time_name_space.rb', line 395 def day super end |
#days ⇒ Series
Extract the days from a Duration type.
1033 1034 1035 |
# File 'lib/polars/date_time_name_space.rb', line 1033 def days super end |
#epoch(tu = "us") ⇒ Series
Get the time passed since the Unix EPOCH in the give time unit.
794 795 796 |
# File 'lib/polars/date_time_name_space.rb', line 794 def epoch(tu = "us") super end |
#hour ⇒ Series
Extract the hour from the underlying DateTime representation.
Applies to Datetime columns.
Returns the hour number from 0 to 23.
468 469 470 |
# File 'lib/polars/date_time_name_space.rb', line 468 def hour super end |
#hours ⇒ Series
Extract the hours from a Duration type.
1064 1065 1066 |
# File 'lib/polars/date_time_name_space.rb', line 1064 def hours super end |
#iso_year ⇒ Series
Extract ISO year from underlying Date representation.
Applies to Date and Datetime columns.
Returns the year number according to the ISO standard. This may not correspond with the calendar year.
199 200 201 |
# File 'lib/polars/date_time_name_space.rb', line 199 def iso_year super end |
#max ⇒ Object
Return maximum as Ruby object.
61 62 63 |
# File 'lib/polars/date_time_name_space.rb', line 61 def max Utils.wrap_s(_s).max end |
#mean ⇒ Object
Return mean as Ruby object.
107 108 109 110 111 |
# File 'lib/polars/date_time_name_space.rb', line 107 def mean s = Utils.wrap_s(_s) out = s.mean.to_i Utils._to_ruby_datetime(out, s.dtype, tu: s.time_unit) end |
#median ⇒ Object
Return median as Ruby object.
83 84 85 86 87 |
# File 'lib/polars/date_time_name_space.rb', line 83 def median s = Utils.wrap_s(_s) out = s.median.to_i Utils._to_ruby_datetime(out, s.dtype, tu: s.time_unit) end |
#microsecond ⇒ Series
Extract the microseconds from the underlying DateTime representation.
Applies to Datetime columns.
659 660 661 |
# File 'lib/polars/date_time_name_space.rb', line 659 def microsecond super end |
#microseconds ⇒ Series
Extract the microseconds from a Duration type.
1192 1193 1194 |
# File 'lib/polars/date_time_name_space.rb', line 1192 def microseconds super end |
#millisecond ⇒ Series
Extract the milliseconds from the underlying DateTime representation.
Applies to Datetime columns.
614 615 616 |
# File 'lib/polars/date_time_name_space.rb', line 614 def millisecond super end |
#milliseconds ⇒ Series
Extract the milliseconds from a Duration type.
1161 1162 1163 |
# File 'lib/polars/date_time_name_space.rb', line 1161 def milliseconds super end |
#min ⇒ Object
Return minimum as Ruby object.
39 40 41 |
# File 'lib/polars/date_time_name_space.rb', line 39 def min Utils.wrap_s(_s).min end |
#minute ⇒ Series
Extract the minutes from the underlying DateTime representation.
Applies to Datetime columns.
Returns the minute number from 0 to 59.
503 504 505 |
# File 'lib/polars/date_time_name_space.rb', line 503 def minute super end |
#minutes ⇒ Series
Extract the minutes from a Duration type.
1095 1096 1097 |
# File 'lib/polars/date_time_name_space.rb', line 1095 def minutes super end |
#month ⇒ Series
Extract the month from the underlying date representation.
Applies to Date and Datetime columns.
Returns the month number starting from 1. The return value ranges from 1 to 12.
274 275 276 |
# File 'lib/polars/date_time_name_space.rb', line 274 def month super end |
#nanosecond ⇒ Series
Extract the nanoseconds from the underlying DateTime representation.
Applies to Datetime columns.
704 705 706 |
# File 'lib/polars/date_time_name_space.rb', line 704 def nanosecond super end |
#nanoseconds ⇒ Series
Extract the nanoseconds from a Duration type.
1223 1224 1225 |
# File 'lib/polars/date_time_name_space.rb', line 1223 def nanoseconds super end |
#offset_by(by) ⇒ Series
Offset this date by a relative time offset.
This differs from Polars.col("foo") + timedelta
in that it can
take months and leap years into account. Note that only a single minus
sign is allowed in the by
string, as the first character.
1291 1292 1293 |
# File 'lib/polars/date_time_name_space.rb', line 1291 def offset_by(by) super end |
#ordinal_day ⇒ Series
Extract ordinal day from underlying date representation.
Applies to Date and Datetime columns.
Returns the day of year starting from 1. The return value ranges from 1 to 366. (The last day of year differs by years.)
431 432 433 |
# File 'lib/polars/date_time_name_space.rb', line 431 def ordinal_day super end |
#quarter ⇒ Series
Extract quarter from underlying Date representation.
Applies to Date and Datetime columns.
Returns the quarter ranging from 1 to 4.
236 237 238 |
# File 'lib/polars/date_time_name_space.rb', line 236 def quarter super end |
#round(every, offset: nil) ⇒ Series
This functionality is currently experimental and may change without it being considered a breaking change.
Divide the date/ datetime range into buckets.
Each date/datetime in the first half of the interval is mapped to the start of its bucket. Each date/datetime in the seconod half of the interval is mapped to the end of its bucket.
The every
and offset
argument are created with the
the following string language:
1ns # 1 nanosecond 1us # 1 microsecond 1ms # 1 millisecond 1s # 1 second 1m # 1 minute 1h # 1 hour 1d # 1 day 1w # 1 week 1mo # 1 calendar month 1y # 1 calendar year
3d12h4m25s # 3 days, 12 hours, 4 minutes, and 25 seconds
1480 1481 1482 |
# File 'lib/polars/date_time_name_space.rb', line 1480 def round(every, offset: nil) super end |
#second(fractional: false) ⇒ Series
Extract seconds from underlying DateTime representation.
Applies to Datetime columns.
Returns the integer second number from 0 to 59, or a floating
point number from 0 < 60 if fractional: true
that includes
any milli/micro/nanosecond component.
569 570 571 |
# File 'lib/polars/date_time_name_space.rb', line 569 def second(fractional: false) super end |
#seconds ⇒ Series
Extract the seconds from a Duration type.
1130 1131 1132 |
# File 'lib/polars/date_time_name_space.rb', line 1130 def seconds super end |
#strftime(fmt) ⇒ Series
Format Date/datetime with a formatting rule.
144 145 146 |
# File 'lib/polars/date_time_name_space.rb', line 144 def strftime(fmt) super end |
#timestamp(tu = "us") ⇒ Series
Return a timestamp in the given time unit.
749 750 751 |
# File 'lib/polars/date_time_name_space.rb', line 749 def (tu = "us") super end |
#truncate(every, offset: nil) ⇒ Series
Divide the date/ datetime range into buckets.
Each date/datetime is mapped to the start of its bucket.
The every
and offset
argument are created with the
the following string language:
1ns # 1 nanosecond 1us # 1 microsecond 1ms # 1 millisecond 1s # 1 second 1m # 1 minute 1h # 1 hour 1d # 1 day 1w # 1 week 1mo # 1 calendar month 1y # 1 calendar year
3d12h4m25s # 3 days, 12 hours, 4 minutes, and 25 seconds
1389 1390 1391 |
# File 'lib/polars/date_time_name_space.rb', line 1389 def truncate(every, offset: nil) super end |
#tz_localize(tz) ⇒ Series
Localize tz-naive Datetime Series to tz-aware Datetime Series.
This method takes a naive Datetime Series and makes this time zone aware. It does not move the time to another time zone.
1004 1005 1006 |
# File 'lib/polars/date_time_name_space.rb', line 1004 def tz_localize(tz) super end |
#week ⇒ Series
Extract the week from the underlying date representation.
Applies to Date and Datetime columns.
Returns the ISO week number starting from 1. The return value ranges from 1 to 53. (The last week of year differs by years.)
312 313 314 |
# File 'lib/polars/date_time_name_space.rb', line 312 def week super end |
#weekday ⇒ Series
Extract the week day from the underlying date representation.
Applies to Date and Datetime columns.
Returns the ISO weekday number where monday = 1 and sunday = 7
355 356 357 |
# File 'lib/polars/date_time_name_space.rb', line 355 def weekday super end |
#with_time_unit(tu) ⇒ Series
Set time unit a Series of dtype Datetime or Duration.
This does not modify underlying data, and should be used to fix an incorrect time unit.
831 832 833 |
# File 'lib/polars/date_time_name_space.rb', line 831 def with_time_unit(tu) super end |
#with_time_zone(tz) ⇒ Series
Set time zone a Series of type Datetime.
910 911 912 |
# File 'lib/polars/date_time_name_space.rb', line 910 def with_time_zone(tz) super end |
#year ⇒ Series
Extract the year from the underlying date representation.
Applies to Date and Datetime columns.
Returns the year number in the calendar date.
177 178 179 |
# File 'lib/polars/date_time_name_space.rb', line 177 def year super end |