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], roll: "raise") ⇒ Series
Offset by
n
business 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.
-
#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]) ⇒ 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.
-
#mean ⇒ Object
Return mean as Ruby object.
-
#median ⇒ Object
Return median 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(fmt) ⇒ Series
Format Date/datetime with a formatting rule.
-
#time ⇒ Object
Extract (local) time.
-
#timestamp(time_unit = "us") ⇒ Series
Return a timestamp in the given time unit.
-
#to_string(format) ⇒ Series
Convert a Date/Time/Datetime column into a String column with the given format.
-
#total_days ⇒ Series
(also: #days)
Extract the days from a Duration type.
-
#total_hours ⇒ Series
(also: #hours)
Extract the hours from a Duration type.
-
#total_microseconds ⇒ Series
(also: #microseconds)
Extract the microseconds from a Duration type.
-
#total_milliseconds ⇒ Series
(also: #milliseconds)
Extract the milliseconds from a Duration type.
-
#total_minutes ⇒ Series
(also: #minutes)
Extract the minutes from a Duration type.
-
#total_nanoseconds ⇒ Series
(also: #nanoseconds)
Extract the nanoseconds from a Duration type.
-
#total_seconds ⇒ Series
(also: #seconds)
Extract the seconds from a Duration type.
-
#truncate(every) ⇒ 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(time_unit) ⇒ 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 |
#add_business_days(n, week_mask: [true, true, true, true, true, false, false], 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
75 76 77 78 79 80 81 |
# File 'lib/polars/date_time_name_space.rb', line 75 def add_business_days( n, week_mask: [true, true, true, true, true, false, false], 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.
1597 1598 1599 |
# File 'lib/polars/date_time_name_space.rb', line 1597 def base_utc_offset super end |
#cast_time_unit(time_unit) ⇒ Series
Cast the underlying data to another time unit. This may lose precision.
940 941 942 |
# File 'lib/polars/date_time_name_space.rb', line 940 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.
268 269 270 |
# File 'lib/polars/date_time_name_space.rb', line 268 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.
1525 1526 1527 |
# File 'lib/polars/date_time_name_space.rb', line 1525 def combine(time, time_unit: "us") super end |
#convert_time_zone(time_zone) ⇒ Series
Set time zone a Series of type Datetime.
974 975 976 |
# File 'lib/polars/date_time_name_space.rb', line 974 def convert_time_zone(time_zone) super end |
#date ⇒ Series
Extract (local) date.
Applies to Date/Datetime columns.
580 581 582 |
# File 'lib/polars/date_time_name_space.rb', line 580 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.)
512 513 514 |
# File 'lib/polars/date_time_name_space.rb', line 512 def day super end |
#dst_offset ⇒ Series
Additional offset currently in effect (typically due to daylight saving time).
1620 1621 1622 |
# File 'lib/polars/date_time_name_space.rb', line 1620 def dst_offset super end |
#epoch(time_unit = "us") ⇒ Series
Get the time passed since the Unix EPOCH in the give time unit.
858 859 860 |
# File 'lib/polars/date_time_name_space.rb', line 858 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.
606 607 608 |
# File 'lib/polars/date_time_name_space.rb', line 606 def hour super end |
#is_business_day(week_mask: [true, true, true, true, true, false, false]) ⇒ 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.
328 329 330 331 332 |
# File 'lib/polars/date_time_name_space.rb', line 328 def is_business_day( week_mask: [true, true, true, true, true, false, false] ) 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.
353 354 355 |
# File 'lib/polars/date_time_name_space.rb', line 353 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.
375 376 377 |
# File 'lib/polars/date_time_name_space.rb', line 375 def iso_year super end |
#max ⇒ Object
Return maximum as Ruby object.
103 104 105 |
# File 'lib/polars/date_time_name_space.rb', line 103 def max Utils.wrap_s(_s).max end |
#mean ⇒ Object
Return mean as Ruby object.
146 147 148 |
# File 'lib/polars/date_time_name_space.rb', line 146 def mean _s.mean end |
#median ⇒ Object
Return median as Ruby object.
127 128 129 |
# File 'lib/polars/date_time_name_space.rb', line 127 def median _s.median end |
#microsecond ⇒ Series
Extract the microseconds from the underlying DateTime representation.
Applies to Datetime columns.
739 740 741 |
# File 'lib/polars/date_time_name_space.rb', line 739 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.
234 235 236 |
# File 'lib/polars/date_time_name_space.rb', line 234 def millennium super end |
#millisecond ⇒ Series
Extract the milliseconds from the underlying DateTime representation.
Applies to Datetime columns.
710 711 712 |
# File 'lib/polars/date_time_name_space.rb', line 710 def millisecond super end |
#min ⇒ Object
Return minimum as Ruby object.
91 92 93 |
# File 'lib/polars/date_time_name_space.rb', line 91 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.
631 632 633 |
# File 'lib/polars/date_time_name_space.rb', line 631 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.
428 429 430 |
# File 'lib/polars/date_time_name_space.rb', line 428 def month super end |
#month_end ⇒ Series
Roll forward to the last day of the month.
1569 1570 1571 |
# File 'lib/polars/date_time_name_space.rb', line 1569 def month_end super end |
#month_start ⇒ Series
Roll backward to the first day of the month.
1547 1548 1549 |
# File 'lib/polars/date_time_name_space.rb', line 1547 def month_start super end |
#nanosecond ⇒ Series
Extract the nanoseconds from the underlying DateTime representation.
Applies to Datetime columns.
768 769 770 |
# File 'lib/polars/date_time_name_space.rb', line 768 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.
1360 1361 1362 |
# File 'lib/polars/date_time_name_space.rb', line 1360 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.)
538 539 540 |
# File 'lib/polars/date_time_name_space.rb', line 538 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.
401 402 403 |
# File 'lib/polars/date_time_name_space.rb', line 401 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.
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 |
# File 'lib/polars/date_time_name_space.rb', line 1660 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.
1059 1060 1061 |
# File 'lib/polars/date_time_name_space.rb', line 1059 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
1510 1511 1512 |
# File 'lib/polars/date_time_name_space.rb', line 1510 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.
681 682 683 |
# File 'lib/polars/date_time_name_space.rb', line 681 def second(fractional: false) super end |
#strftime(fmt) ⇒ Series
Format Date/datetime with a formatting rule.
200 201 202 |
# File 'lib/polars/date_time_name_space.rb', line 200 def strftime(fmt) super end |
#time ⇒ Object
Extract (local) time.
Applies to Date/Datetime/Time columns.
559 560 561 |
# File 'lib/polars/date_time_name_space.rb', line 559 def time super end |
#timestamp(time_unit = "us") ⇒ Series
Return a timestamp in the given time unit.
813 814 815 |
# File 'lib/polars/date_time_name_space.rb', line 813 def (time_unit = "us") super end |
#to_string(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.
176 177 178 |
# File 'lib/polars/date_time_name_space.rb', line 176 def to_string(format) super end |
#total_days ⇒ Series Also known as: days
Extract the days from a Duration type.
1093 1094 1095 |
# File 'lib/polars/date_time_name_space.rb', line 1093 def total_days super end |
#total_hours ⇒ Series Also known as: hours
Extract the hours from a Duration type.
1125 1126 1127 |
# File 'lib/polars/date_time_name_space.rb', line 1125 def total_hours super end |
#total_microseconds ⇒ Series Also known as: microseconds
Extract the microseconds from a Duration type.
1257 1258 1259 |
# File 'lib/polars/date_time_name_space.rb', line 1257 def total_microseconds super end |
#total_milliseconds ⇒ Series Also known as: milliseconds
Extract the milliseconds from a Duration type.
1225 1226 1227 |
# File 'lib/polars/date_time_name_space.rb', line 1225 def total_milliseconds super end |
#total_minutes ⇒ Series Also known as: minutes
Extract the minutes from a Duration type.
1157 1158 1159 |
# File 'lib/polars/date_time_name_space.rb', line 1157 def total_minutes super end |
#total_nanoseconds ⇒ Series Also known as: nanoseconds
Extract the nanoseconds from a Duration type.
1289 1290 1291 |
# File 'lib/polars/date_time_name_space.rb', line 1289 def total_nanoseconds super end |
#total_seconds ⇒ Series Also known as: seconds
Extract the seconds from a Duration type.
1193 1194 1195 |
# File 'lib/polars/date_time_name_space.rb', line 1193 def total_seconds 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
1429 1430 1431 |
# File 'lib/polars/date_time_name_space.rb', line 1429 def truncate(every) 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.
1072 1073 1074 |
# File 'lib/polars/date_time_name_space.rb', line 1072 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.)
455 456 457 |
# File 'lib/polars/date_time_name_space.rb', line 455 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
484 485 486 |
# File 'lib/polars/date_time_name_space.rb', line 484 def weekday super end |
#with_time_unit(time_unit) ⇒ 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.
895 896 897 |
# File 'lib/polars/date_time_name_space.rb', line 895 def with_time_unit(time_unit) 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.
290 291 292 |
# File 'lib/polars/date_time_name_space.rb', line 290 def year super end |