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.
-
#add_business_days(n, week_mask: [true, true, true, true, true, false, false], holidays: [], roll: "raise") ⇒ Series
Offset by
nbusiness days. -
#base_utc_offset ⇒ Series
Base offset from UTC.
-
#cast_time_unit(time_unit) ⇒ Series
Cast the underlying data to another time unit.
-
#century ⇒ Series
Extract the century from underlying representation.
-
#combine(time, time_unit: "us") ⇒ Series
Create a naive Datetime from an existing Date/Datetime expression and a Time.
-
#convert_time_zone(time_zone) ⇒ Series
Set time zone a Series of type Datetime.
-
#date ⇒ Series
Extract (local) date.
-
#day ⇒ Series
Extract the day from the underlying date representation.
-
#days_in_month ⇒ Series
Extract the number of days in the month from the underlying date representation.
-
#dst_offset ⇒ Series
Additional offset currently in effect (typically due to daylight saving time).
-
#epoch(time_unit = "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.
-
#is_business_day(week_mask: [true, true, true, true, true, false, false], holidays: []) ⇒ Series
Determine whether each day lands on a business day.
-
#is_leap_year ⇒ Series
Determine whether the year of the underlying date representation is a leap year.
-
#iso_year ⇒ Series
Extract ISO year from underlying Date representation.
-
#max ⇒ Object
Return maximum as Ruby object.
-
#microsecond ⇒ Series
Extract the microseconds from the underlying DateTime representation.
-
#millennium ⇒ Series
Extract the millennium from underlying representation.
-
#millisecond ⇒ Series
Extract the milliseconds from the underlying DateTime representation.
-
#min ⇒ Object
Return minimum as Ruby object.
-
#minute ⇒ Series
Extract the minutes from the underlying DateTime representation.
-
#month ⇒ Series
Extract the month from the underlying date representation.
-
#month_end ⇒ Series
Roll forward to the last day of the month.
-
#month_start ⇒ Series
Roll backward to the first day of the month.
-
#nanosecond ⇒ Series
Extract the nanoseconds from the underlying DateTime representation.
-
#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(year: nil, month: nil, day: nil, hour: nil, minute: nil, second: nil, microsecond: nil, ambiguous: "raise") ⇒ Series
Replace time unit.
-
#replace_time_zone(time_zone, ambiguous: "raise", non_existent: "raise") ⇒ Series
Cast time zone for a Series of type Datetime.
-
#round(every) ⇒ Series
Divide the date/ datetime range into buckets.
-
#second(fractional: false) ⇒ Series
Extract seconds from underlying DateTime representation.
-
#strftime(format) ⇒ Series
Convert a Date/Time/Datetime column into a String column with the given format.
-
#time ⇒ Object
Extract (local) time.
-
#timestamp(time_unit = "us") ⇒ Series
Return a timestamp in the given time unit.
-
#to_string(format = nil) ⇒ Series
Convert a Date/Time/Datetime column into a String column with the given format.
-
#total_days(fractional: false) ⇒ Series
Extract the days from a Duration type.
-
#total_hours(fractional: false) ⇒ Series
Extract the hours from a Duration type.
-
#total_microseconds(fractional: false) ⇒ Series
Extract the microseconds from a Duration type.
-
#total_milliseconds(fractional: false) ⇒ Series
Extract the milliseconds from a Duration type.
-
#total_minutes(fractional: false) ⇒ Series
Extract the minutes from a Duration type.
-
#total_nanoseconds(fractional: false) ⇒ Series
Extract the nanoseconds from a Duration type.
-
#total_seconds(fractional: false) ⇒ Series
Extract the seconds from a Duration type.
-
#truncate(every) ⇒ Series
Divide the date/ datetime range into buckets.
-
#week ⇒ Series
Extract the week from the underlying date representation.
-
#weekday ⇒ Series
Extract the week day from the underlying date representation.
-
#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 |
#add_business_days(n, week_mask: [true, true, true, true, true, false, false], holidays: [], roll: "raise") ⇒ Series
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Offset by n business days.
roll What to do when the start date lands on a non-business day. Options are:
'raise': raise an error'forward': move to the next business day'backward': move to the previous business day
77 78 79 80 81 82 83 84 |
# File 'lib/polars/date_time_name_space.rb', line 77 def add_business_days( n, week_mask: [true, true, true, true, true, false, false], holidays: [], roll: "raise" ) super end |
#base_utc_offset ⇒ Series
Base offset from UTC.
This is usually constant for all datetimes in a given time zone, but may vary in the rare case that a country switches time zone, like Samoa (Apia) did at the end of 2011.
1571 1572 1573 |
# File 'lib/polars/date_time_name_space.rb', line 1571 def base_utc_offset super end |
#cast_time_unit(time_unit) ⇒ Series
Cast the underlying data to another time unit. This may lose precision.
897 898 899 |
# File 'lib/polars/date_time_name_space.rb', line 897 def cast_time_unit(time_unit) super end |
#century ⇒ Series
Extract the century from underlying representation.
Applies to Date and Datetime columns.
Returns the century number in the calendar date.
233 234 235 |
# File 'lib/polars/date_time_name_space.rb', line 233 def century super end |
#combine(time, time_unit: "us") ⇒ Series
Create a naive Datetime from an existing Date/Datetime expression and a Time.
If the underlying expression is a Datetime then its time component is replaced, and if it is a Date then a new Datetime is created by combining the two values.
1499 1500 1501 |
# File 'lib/polars/date_time_name_space.rb', line 1499 def combine(time, time_unit: "us") super end |
#convert_time_zone(time_zone) ⇒ Series
Set time zone a Series of type Datetime.
931 932 933 |
# File 'lib/polars/date_time_name_space.rb', line 931 def convert_time_zone(time_zone) super end |
#date ⇒ Series
Extract (local) date.
Applies to Date/Datetime columns.
574 575 576 |
# File 'lib/polars/date_time_name_space.rb', line 574 def date 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.)
506 507 508 |
# File 'lib/polars/date_time_name_space.rb', line 506 def day super end |
#days_in_month ⇒ Series
Extract the number of days in the month from the underlying date representation.
Applies to Date and Datetime columns.
Returns the number of days in the month. The return value ranges from 28 to 31.
422 423 424 |
# File 'lib/polars/date_time_name_space.rb', line 422 def days_in_month super end |
#dst_offset ⇒ Series
Additional offset currently in effect (typically due to daylight saving time).
1594 1595 1596 |
# File 'lib/polars/date_time_name_space.rb', line 1594 def dst_offset super end |
#epoch(time_unit = "us") ⇒ Series
Get the time passed since the Unix EPOCH in the give time unit.
852 853 854 |
# File 'lib/polars/date_time_name_space.rb', line 852 def epoch(time_unit = "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.
600 601 602 |
# File 'lib/polars/date_time_name_space.rb', line 600 def hour super end |
#is_business_day(week_mask: [true, true, true, true, true, false, false], holidays: []) ⇒ Series
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Determine whether each day lands on a business day.
295 296 297 298 299 300 |
# File 'lib/polars/date_time_name_space.rb', line 295 def is_business_day( week_mask: [true, true, true, true, true, false, false], holidays: [] ) super end |
#is_leap_year ⇒ Series
Determine whether the year of the underlying date representation is a leap year.
Applies to Date and Datetime columns.
321 322 323 |
# File 'lib/polars/date_time_name_space.rb', line 321 def is_leap_year 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.
343 344 345 |
# File 'lib/polars/date_time_name_space.rb', line 343 def iso_year super end |
#max ⇒ Object
Return maximum as Ruby object.
106 107 108 |
# File 'lib/polars/date_time_name_space.rb', line 106 def max Utils.wrap_s(_s).max end |
#microsecond ⇒ Series
Extract the microseconds from the underlying DateTime representation.
Applies to Datetime columns.
733 734 735 |
# File 'lib/polars/date_time_name_space.rb', line 733 def microsecond super end |
#millennium ⇒ Series
Extract the millennium from underlying representation.
Applies to Date and Datetime columns.
Returns the millennium number in the calendar date.
199 200 201 |
# File 'lib/polars/date_time_name_space.rb', line 199 def millennium super end |
#millisecond ⇒ Series
Extract the milliseconds from the underlying DateTime representation.
Applies to Datetime columns.
704 705 706 |
# File 'lib/polars/date_time_name_space.rb', line 704 def millisecond super end |
#min ⇒ Object
Return minimum as Ruby object.
94 95 96 |
# File 'lib/polars/date_time_name_space.rb', line 94 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.
625 626 627 |
# File 'lib/polars/date_time_name_space.rb', line 625 def minute 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.
396 397 398 |
# File 'lib/polars/date_time_name_space.rb', line 396 def month super end |
#month_end ⇒ Series
Roll forward to the last day of the month.
1543 1544 1545 |
# File 'lib/polars/date_time_name_space.rb', line 1543 def month_end super end |
#month_start ⇒ Series
Roll backward to the first day of the month.
1521 1522 1523 |
# File 'lib/polars/date_time_name_space.rb', line 1521 def month_start super end |
#nanosecond ⇒ Series
Extract the nanoseconds from the underlying DateTime representation.
Applies to Datetime columns.
762 763 764 |
# File 'lib/polars/date_time_name_space.rb', line 762 def nanosecond 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.
1320 1321 1322 |
# File 'lib/polars/date_time_name_space.rb', line 1320 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.)
532 533 534 |
# File 'lib/polars/date_time_name_space.rb', line 532 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.
369 370 371 |
# File 'lib/polars/date_time_name_space.rb', line 369 def quarter super end |
#replace(year: nil, month: nil, day: nil, hour: nil, minute: nil, second: nil, microsecond: nil, ambiguous: "raise") ⇒ Series
Replace time unit.
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 |
# File 'lib/polars/date_time_name_space.rb', line 1634 def replace( year: nil, month: nil, day: nil, hour: nil, minute: nil, second: nil, microsecond: nil, ambiguous: "raise" ) super end |
#replace_time_zone(time_zone, ambiguous: "raise", non_existent: "raise") ⇒ Series
Cast time zone for a Series of type Datetime.
Different from with_time_zone, this will also modify
the underlying timestamp.
1016 1017 1018 |
# File 'lib/polars/date_time_name_space.rb', line 1016 def replace_time_zone(time_zone, ambiguous: "raise", non_existent: "raise") super end |
#round(every) ⇒ 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
1470 1471 1472 |
# File 'lib/polars/date_time_name_space.rb', line 1470 def round(every) 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.
675 676 677 |
# File 'lib/polars/date_time_name_space.rb', line 675 def second(fractional: false) super end |
#strftime(format) ⇒ Series
Convert a Date/Time/Datetime column into a String column with the given format.
Similar to cast(Polars::String), but this method allows you to customize the
formatting of the resulting string.
165 166 167 |
# File 'lib/polars/date_time_name_space.rb', line 165 def strftime(format) super end |
#time ⇒ Object
Extract (local) time.
Applies to Date/Datetime/Time columns.
553 554 555 |
# File 'lib/polars/date_time_name_space.rb', line 553 def time super end |
#timestamp(time_unit = "us") ⇒ Series
Return a timestamp in the given time unit.
807 808 809 |
# File 'lib/polars/date_time_name_space.rb', line 807 def (time_unit = "us") super end |
#to_string(format = nil) ⇒ Series
Convert a Date/Time/Datetime column into a String column with the given format.
Similar to cast(Polars::String), but this method allows you to customize the
formatting of the resulting string.
136 137 138 |
# File 'lib/polars/date_time_name_space.rb', line 136 def to_string(format = nil) super end |
#total_days(fractional: false) ⇒ Series
Extract the days from a Duration type.
1040 1041 1042 |
# File 'lib/polars/date_time_name_space.rb', line 1040 def total_days(fractional: false) super end |
#total_hours(fractional: false) ⇒ Series
Extract the hours from a Duration type.
1074 1075 1076 |
# File 'lib/polars/date_time_name_space.rb', line 1074 def total_hours(fractional: false) super end |
#total_microseconds(fractional: false) ⇒ Series
Extract the microseconds from a Duration type.
1214 1215 1216 |
# File 'lib/polars/date_time_name_space.rb', line 1214 def total_microseconds(fractional: false) super end |
#total_milliseconds(fractional: false) ⇒ Series
Extract the milliseconds from a Duration type.
1180 1181 1182 |
# File 'lib/polars/date_time_name_space.rb', line 1180 def total_milliseconds(fractional: false) super end |
#total_minutes(fractional: false) ⇒ Series
Extract the minutes from a Duration type.
1108 1109 1110 |
# File 'lib/polars/date_time_name_space.rb', line 1108 def total_minutes(fractional: false) super end |
#total_nanoseconds(fractional: false) ⇒ Series
Extract the nanoseconds from a Duration type.
1250 1251 1252 |
# File 'lib/polars/date_time_name_space.rb', line 1250 def total_nanoseconds(fractional: false) super end |
#total_seconds(fractional: false) ⇒ Series
Extract the seconds from a Duration type.
1146 1147 1148 |
# File 'lib/polars/date_time_name_space.rb', line 1146 def total_seconds(fractional: false) super end |
#truncate(every) ⇒ 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) 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.)
449 450 451 |
# File 'lib/polars/date_time_name_space.rb', line 449 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
478 479 480 |
# File 'lib/polars/date_time_name_space.rb', line 478 def weekday 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.
255 256 257 |
# File 'lib/polars/date_time_name_space.rb', line 255 def year super end |