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.
-
#convert_time_zone(tz) ⇒ Series
Set time zone 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.
-
#replace_time_zone(tz) ⇒ Series
Cast time zone for a Series of type Datetime.
-
#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, use_earliest: 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.
-
#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.
870 871 872 |
# File 'lib/polars/date_time_name_space.rb', line 870 def cast_time_unit(tu) super end |
#convert_time_zone(tz) ⇒ Series
Set time zone a Series of type Datetime.
904 905 906 |
# File 'lib/polars/date_time_name_space.rb', line 904 def convert_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.)
389 390 391 |
# File 'lib/polars/date_time_name_space.rb', line 389 def day super end |
#days ⇒ Series
Extract the days from a Duration type.
1027 1028 1029 |
# File 'lib/polars/date_time_name_space.rb', line 1027 def days super end |
#epoch(tu = "us") ⇒ Series
Get the time passed since the Unix EPOCH in the give time unit.
788 789 790 |
# File 'lib/polars/date_time_name_space.rb', line 788 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.
462 463 464 |
# File 'lib/polars/date_time_name_space.rb', line 462 def hour super end |
#hours ⇒ Series
Extract the hours from a Duration type.
1058 1059 1060 |
# File 'lib/polars/date_time_name_space.rb', line 1058 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.
193 194 195 |
# File 'lib/polars/date_time_name_space.rb', line 193 def iso_year super end |
#max ⇒ Object
Return maximum as Ruby object.
41 42 43 |
# File 'lib/polars/date_time_name_space.rb', line 41 def max Utils.wrap_s(_s).max end |
#mean ⇒ Object
Return mean as Ruby object.
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/polars/date_time_name_space.rb', line 94 def mean s = Utils.wrap_s(_s) out = s.mean.to_i if !out.nil? if s.dtype == Date return Utils._to_ruby_date(out.to_i) else return Utils._to_ruby_datetime(out.to_i, s.time_unit) end end nil end |
#median ⇒ Object
Return median as Ruby object.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/polars/date_time_name_space.rb', line 63 def median s = Utils.wrap_s(_s) out = s.median if !out.nil? if s.dtype == Date return Utils._to_ruby_date(out.to_i) else return Utils._to_ruby_datetime(out.to_i, s.time_unit) end end nil end |
#microsecond ⇒ Series
Extract the microseconds from the underlying DateTime representation.
Applies to Datetime columns.
653 654 655 |
# File 'lib/polars/date_time_name_space.rb', line 653 def microsecond super end |
#microseconds ⇒ Series
Extract the microseconds from a Duration type.
1186 1187 1188 |
# File 'lib/polars/date_time_name_space.rb', line 1186 def microseconds super end |
#millisecond ⇒ Series
Extract the milliseconds from the underlying DateTime representation.
Applies to Datetime columns.
608 609 610 |
# File 'lib/polars/date_time_name_space.rb', line 608 def millisecond super end |
#milliseconds ⇒ Series
Extract the milliseconds from a Duration type.
1155 1156 1157 |
# File 'lib/polars/date_time_name_space.rb', line 1155 def milliseconds super end |
#min ⇒ Object
Return minimum as Ruby object.
29 30 31 |
# File 'lib/polars/date_time_name_space.rb', line 29 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.
497 498 499 |
# File 'lib/polars/date_time_name_space.rb', line 497 def minute super end |
#minutes ⇒ Series
Extract the minutes from a Duration type.
1089 1090 1091 |
# File 'lib/polars/date_time_name_space.rb', line 1089 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.
268 269 270 |
# File 'lib/polars/date_time_name_space.rb', line 268 def month super end |
#nanosecond ⇒ Series
Extract the nanoseconds from the underlying DateTime representation.
Applies to Datetime columns.
698 699 700 |
# File 'lib/polars/date_time_name_space.rb', line 698 def nanosecond super end |
#nanoseconds ⇒ Series
Extract the nanoseconds from a Duration type.
1217 1218 1219 |
# File 'lib/polars/date_time_name_space.rb', line 1217 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.
1285 1286 1287 |
# File 'lib/polars/date_time_name_space.rb', line 1285 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.)
425 426 427 |
# File 'lib/polars/date_time_name_space.rb', line 425 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.
230 231 232 |
# File 'lib/polars/date_time_name_space.rb', line 230 def quarter super end |
#replace_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.
985 986 987 |
# File 'lib/polars/date_time_name_space.rb', line 985 def replace_time_zone(tz) 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
1474 1475 1476 |
# File 'lib/polars/date_time_name_space.rb', line 1474 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.
563 564 565 |
# File 'lib/polars/date_time_name_space.rb', line 563 def second(fractional: false) super end |
#seconds ⇒ Series
Extract the seconds from a Duration type.
1124 1125 1126 |
# File 'lib/polars/date_time_name_space.rb', line 1124 def seconds super end |
#strftime(fmt) ⇒ Series
Format Date/datetime with a formatting rule.
138 139 140 |
# File 'lib/polars/date_time_name_space.rb', line 138 def strftime(fmt) super end |
#timestamp(tu = "us") ⇒ Series
Return a timestamp in the given time unit.
743 744 745 |
# File 'lib/polars/date_time_name_space.rb', line 743 def (tu = "us") super end |
#truncate(every, offset: nil, use_earliest: 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
1383 1384 1385 |
# File 'lib/polars/date_time_name_space.rb', line 1383 def truncate(every, offset: nil, use_earliest: 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.
998 999 1000 |
# File 'lib/polars/date_time_name_space.rb', line 998 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.)
306 307 308 |
# File 'lib/polars/date_time_name_space.rb', line 306 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
349 350 351 |
# File 'lib/polars/date_time_name_space.rb', line 349 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.
825 826 827 |
# File 'lib/polars/date_time_name_space.rb', line 825 def with_time_unit(tu) 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.
171 172 173 |
# File 'lib/polars/date_time_name_space.rb', line 171 def year super end |