Skip to main content

DatetimeAccessor

Struct DatetimeAccessor 

Source
pub struct DatetimeAccessor<'a> { /* private fields */ }

Implementations§

Source§

impl DatetimeAccessor<'_>

Source

pub fn year(&self) -> Result<Series, FrameError>

Extract year component.

Matches pd.Series.dt.year.

Source

pub fn month(&self) -> Result<Series, FrameError>

Extract month component (1-12).

Matches pd.Series.dt.month.

Source

pub fn day(&self) -> Result<Series, FrameError>

Extract day component (1-31).

Matches pd.Series.dt.day.

Source

pub fn hour(&self) -> Result<Series, FrameError>

Extract hour component (0-23).

Matches pd.Series.dt.hour.

Source

pub fn minute(&self) -> Result<Series, FrameError>

Extract minute component (0-59).

Matches pd.Series.dt.minute.

Source

pub fn second(&self) -> Result<Series, FrameError>

Extract second component (0-59).

Matches pd.Series.dt.second.

Source

pub fn microsecond(&self) -> Result<Series, FrameError>

Extract microsecond component (0-999999).

Matches pd.Series.dt.microsecond.

Source

pub fn nanosecond(&self) -> Result<Series, FrameError>

Extract nanosecond component (0-999).

Matches pd.Series.dt.nanosecond.

Source

pub fn dayofweek(&self) -> Result<Series, FrameError>

Extract day of week (Monday=0, Sunday=6).

Matches pd.Series.dt.dayofweek / pd.Series.dt.weekday.

Source

pub fn weekday(&self) -> Result<Series, FrameError>

Alias for dayofweek(). Matches pd.Series.dt.weekday.

Source

pub fn day_of_week(&self) -> Result<Series, FrameError>

Alias for dayofweek(). Matches pd.Series.dt.day_of_week.

Source

pub fn date(&self) -> Result<Series, FrameError>

Extract date part as string (YYYY-MM-DD).

Matches pd.Series.dt.date.

Source

pub fn time(&self) -> Result<Series, FrameError>

Extract time part as string (HH:MM:SS).

Matches pd.Series.dt.time.

Source

pub fn tz(&self) -> Result<Series, FrameError>

Extract timezone info from datetime strings.

Returns the timezone suffix (e.g., “+00:00”, “Z”, “-05:00”) or None for naive (timezone-unaware) datetimes.

Matches pd.Series.dt.tz inspection pattern.

Source

pub fn timetz(&self) -> Result<Series, FrameError>

Extract time with timezone info preserved (HH:MM:SS+TZ).

Matches pd.Series.dt.timetz which returns time objects with tzinfo. For naive datetimes, returns time without timezone suffix.

Source

pub fn components(&self) -> Result<DataFrame, FrameError>

Returns DataFrame with datetime components (year, month, day, hour, minute, second).

Similar to pd.Series.dt.components for Timedelta, but for datetime values.

Source

pub fn quarter(&self) -> Result<Series, FrameError>

Extract quarter (1-4).

Matches pd.Series.dt.quarter.

Source

pub fn dayofyear(&self) -> Result<Series, FrameError>

Extract day of year (1-366).

Matches pd.Series.dt.dayofyear.

Source

pub fn day_of_year(&self) -> Result<Series, FrameError>

Alias for dayofyear(). Matches pd.Series.dt.day_of_year.

Source

pub fn weekofyear(&self) -> Result<Series, FrameError>

Extract ISO week number (1-53).

Matches pd.Series.dt.isocalendar().week.

Source

pub fn week(&self) -> Result<Series, FrameError>

Alias for weekofyear().

⚠️ NOT A PARITY SURFACE: Series.dt.week was REMOVED in pandas 2.0. Measured on 2.2.3, .dt.week AND .dt.weekofyear both raise AttributeError; the replacement is .dt.isocalendar().week, which weekofyear() implements. FP keeps this alias as a SUPERSET for callers written against pandas 1.x – do not cite it as parity evidence.

The removal was scoped to the Series accessor: the scalar pd.Timestamp.week and pd.PeriodIndex.week BOTH still exist on 2.2.3.

Source

pub fn isocalendar(&self) -> Result<DataFrame, FrameError>

Returns a DataFrame with ISO calendar columns: year, week, day.

Matches pd.Series.dt.isocalendar().

Source

pub fn is_month_start(&self) -> Result<Series, FrameError>

Check if date is the first day of the month.

Matches pd.Series.dt.is_month_start.

Source

pub fn is_month_end(&self) -> Result<Series, FrameError>

Check if date is the last day of the month.

Matches pd.Series.dt.is_month_end.

Source

pub fn is_quarter_start(&self) -> Result<Series, FrameError>

Check if date is the first day of a quarter.

Matches pd.Series.dt.is_quarter_start.

Source

pub fn is_quarter_end(&self) -> Result<Series, FrameError>

Check if date is the last day of a quarter.

Matches pd.Series.dt.is_quarter_end.

Source

pub fn strftime(&self, format: &str) -> Result<Series, FrameError>

Format datetime using strftime-like directives.

Matches pd.Series.dt.strftime(format): Python’s directives, see fp_types::strftime_python (only %Y %m %d %H %M %S were known; the rest printed literally, so ‘%B %d’ gave ‘%B 05’); a tz-aware column formats its wall clock with the zone’s offset / abbreviation (it formatted the UTC clock). NaT is missing.

Source

pub fn days_in_month(&self) -> Result<Series, FrameError>

Number of days in the month of each datetime.

Matches pd.Series.dt.days_in_month.

Source

pub fn daysinmonth(&self) -> Result<Series, FrameError>

Alias for days_in_month(). Matches pd.Series.dt.daysinmonth.

Source

pub fn is_leap_year(&self) -> Result<Series, FrameError>

Whether the year of each datetime is a leap year.

Matches pd.Series.dt.is_leap_year.

Source

pub fn is_year_start(&self) -> Result<Series, FrameError>

Whether each datetime is the start of the year (Jan 1).

Matches pd.Series.dt.is_year_start.

Source

pub fn is_year_end(&self) -> Result<Series, FrameError>

Whether each datetime is the end of the year (Dec 31).

Matches pd.Series.dt.is_year_end.

Source

pub fn month_name(&self) -> Result<Series, FrameError>

Full month name (e.g. “January”) for each datetime.

Matches pd.Series.dt.month_name().

Source

pub fn day_name(&self) -> Result<Series, FrameError>

Full day name (e.g. “Monday”) for each datetime.

Matches pd.Series.dt.day_name(). Uses Zeller’s congruence.

Source

pub fn total_seconds(&self) -> Result<Series, FrameError>

Total seconds for each timedelta value.

Per br-frankenpandas-i9bah: pandas dt.total_seconds() is for timedelta dtype, not datetime. Returns Float64 (fractional seconds supported). Errors if the series contains datetime strings (pandas has no dt.total_seconds() for datetime).

Source

pub fn to_period(&self, freq: &str) -> Result<Series, FrameError>

Convert each datetime VALUE to its period label. Matches pd.Series.dt.to_period(freq).

⚠️ NOT THE SAME OPERATION AS Series::to_period, which converts the INDEX — pandas draws the same distinction (Series.to_period is the index one, Series.dt.to_period is the values one). FrankenPandas had only the index form, so .dt.to_period was absent.

MEASURED, pandas 2.2.3, on [‘2024-03-10 01:30:45’, ‘2024-12-31 23:59:59’, NaT]:

  'Y' -> 2024,    2024,       NaT
  'Q' -> 2024Q1,  2024Q4,     NaT
  'M' -> 2024-03, 2024-12,    NaT
  'D' -> 2024-03-10, 2024-12-31, NaT

IMPLEMENTED BY REUSING THE INDEX PATH rather than re-deriving the calendar arithmetic: the values are lifted to IndexLabels, run through period_index_from_datetime_like_index, and read back. That inherits the anchored-frequency handling (W-MON.., Y-JAN.., Q-anchored), the NaT convention and the contiguous-buffer fast path already tested there, none of which would survive a hand-rolled second implementation.

Output is Utf8 period labels, following the convention Series::to_period documents — canonical period strings until a dedicated Period value variant lands.

Source

pub fn to_pytimedelta(&self) -> Result<Series, FrameError>

Reduce each Timedelta to Python datetime.timedelta resolution. Matches pd.Series.dt.to_pytimedelta().

⚠️ IT ROUNDS, IT DOES NOT TRUNCATE, and the tie rule is HALF-TO-EVEN. I assumed truncation first; pandas disagrees. MEASURED, 2.2.3, nanoseconds in -> nanoseconds out:

     1 ->     0        -1 ->     0
   999 ->  1000      -999 -> -1000     (rounds AWAY from zero, not toward)
  1001 ->  1000     -1001 -> -1000
   500 ->     0       -500 ->     0     tie -> 0 is even
  1500 ->  2000      -1500 -> -2000     tie -> 2 is even
  2500 ->  2000      -2500 -> -2000     tie -> 2 is even, NOT 3
  3500 ->  4000

Half-away-from-zero reproduces only 3 of those 7 tie cases, so the distinction is observable rather than academic. This is the same rule Self::round documents for datetimes.

The result stays a Timedelta64 column: the observable effect of to_pytimedelta is the RESOLUTION LOSS, and FrankenPandas has no Python object dtype to model the container. NaT stays NaT.

Source

pub fn days(&self) -> Result<Series, FrameError>

Whole days of each Timedelta. Matches pd.Series.dt.days.

MEASURED, pandas 2.2.3, pd.to_timedelta([1, None, -1, 90061.5], unit='s'):

  .dt.days         -> [0.0, nan, -1.0, 1.0]        dtype float64
  .dt.seconds      -> [1.0, nan, 86399.0, 3661.0]
  .dt.microseconds -> [0.0, nan, 0.0, 500000.0]
  .dt.nanoseconds  -> [0.0, nan, 0.0, 0.0]

FLOAT64, NOT Int64, AND THAT IS NOT A CHOICE. NaT must be representable in the output, and numpy int64 cannot hold a missing value, so pandas promotes the whole component column — the same dtype-level rule measured across seven producers for the br-frankenpandas-09ygw / b8n0q cluster.

The negative case is the one an implementation gets wrong: -1s is days == -1 and seconds == 86399, not 0/-1, because the split is EUCLIDEAN. fp_types::Timedelta already uses div_euclid/rem_euclid, so this delegates rather than re-deriving it.

Source

pub fn seconds(&self) -> Result<Series, FrameError>

Seconds within the day (0..=86399). Matches pd.Series.dt.seconds. See Self::days for the measured table and the float64 rationale.

Source

pub fn microseconds(&self) -> Result<Series, FrameError>

Microseconds within the second (0..=999_999). Matches pd.Series.dt.microseconds. See Self::days.

Source

pub fn nanoseconds(&self) -> Result<Series, FrameError>

Nanoseconds within the microsecond (0..=999). Matches pd.Series.dt.nanoseconds. See Self::days.

Source

pub fn to_timestamp(&self) -> Result<Series, FrameError>

Convert period-like strings to full timestamp strings.

Matches pd.Series.dt.to_timestamp(). For date-only strings (“YYYY-MM-DD”), appends “00:00:00” to produce a full datetime. Month periods (“YYYY-MM”) become “YYYY-MM-01 00:00:00”. Year periods (“YYYY”) become “YYYY-01-01 00:00:00”.

Source

pub fn to_timestamp_with_how(&self, how: &str) -> Result<Series, FrameError>

Convert period-like strings to full timestamp strings using the requested boundary.

Matches pd.Series.dt.to_timestamp(how='start'|'end') for year/month/day-like periods.

Source

pub fn to_pydatetime(&self) -> Result<Series, FrameError>

Convert datetime-like strings to Python-datetime-compatible strings.

Matches pd.Series.dt.to_pydatetime(warn=...) in observable value output. Nanoseconds beyond microsecond precision are truncated to match Python’s datetime precision.

Source

pub fn to_pydatetime_with_warn(&self, warn: bool) -> Result<Series, FrameError>

Convert datetime-like strings to Python-datetime-compatible strings, optionally suppressing pandas’ nanosecond-loss warning.

Source

pub fn floor(&self, freq: &str) -> Result<Series, FrameError>

Round each datetime down (floor) to the given frequency.

Matches pd.Series.dt.floor(freq). Supported frequencies: “D”, “h”/“H”, “min”/“T”, “s”/“S”, “ms”, “us”, “ns”.

Source

pub fn ceil(&self, freq: &str) -> Result<Series, FrameError>

Round each datetime up (ceil) to the given frequency.

Matches pd.Series.dt.ceil(freq). Same frequencies as floor.

Source

pub fn round(&self, freq: &str) -> Result<Series, FrameError>

Round each datetime to the nearest given frequency.

Matches pd.Series.dt.round(freq). Ties round half-to-even on the frequency-unit count, like pandas. Same frequencies as floor.

Source

pub fn floor_with_options( &self, freq: &str, options: TzLocalizeOptions, ) -> Result<Series, FrameError>

floor with pandas’ ambiguous / nonexistent: a tz-aware column’s rounded wall clock goes back into its zone under them (a DST gap or repeat was always an error; br-frankenpandas-cnpw1).

Source

pub fn ceil_with_options( &self, freq: &str, options: TzLocalizeOptions, ) -> Result<Series, FrameError>

ceil with pandas’ ambiguous / nonexistent (see Self::floor_with_options).

Source

pub fn round_with_options( &self, freq: &str, options: TzLocalizeOptions, ) -> Result<Series, FrameError>

round with pandas’ ambiguous / nonexistent (see Self::floor_with_options).

Source

pub fn normalize(&self) -> Result<Series, FrameError>

Normalize each datetime to midnight (set time to 00:00:00).

Matches pd.Series.dt.normalize(). Equivalent to floor("D").

Source

pub fn tz_localize(&self, tz: Option<&str>) -> Result<Series, FrameError>

Localize tz-naive datetimes to a timezone or remove existing timezone data.

Matches pd.Series.dt.tz_localize(tz). Some(tz) appends timezone info to each naive datetime string. None removes timezone info while keeping the local clock-time representation.

Source

pub fn tz_localize_with_options( &self, tz: Option<&str>, options: TzLocalizeOptions, ) -> Result<Series, FrameError>

Localize tz-naive datetimes with explicit DST ambiguity/nonexistence policy.

Source

pub fn tz_convert(&self, tz: Option<&str>) -> Result<Series, FrameError>

Convert timezone-aware datetimes to a different timezone or to UTC-naive values.

Matches pd.Series.dt.tz_convert(tz). Some(tz) adjusts the UTC offset and replaces the timezone suffix. None converts through UTC and then removes timezone information.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DatetimeAccessor<'a>

§

impl<'a> !UnwindSafe for DatetimeAccessor<'a>

§

impl<'a> Freeze for DatetimeAccessor<'a>

§

impl<'a> Send for DatetimeAccessor<'a>

§

impl<'a> Sync for DatetimeAccessor<'a>

§

impl<'a> Unpin for DatetimeAccessor<'a>

§

impl<'a> UnsafeUnpin for DatetimeAccessor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.