Skip to content

Commit

Permalink
fix[rust]: only consider dt series equal if they have the same tz (#5025
Browse files Browse the repository at this point in the history
)
  • Loading branch information
matteosantama committed Sep 29, 2022
1 parent b067b15 commit fb716e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions polars/polars-core/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@ impl Series {
}

/// Check if all values in series are equal where `None == None` evaluates to `true`.
/// Two `Datetime` series are *not* equal if their timezones are different, regardless
/// if they represent the same UTC time or not.
pub fn series_equal_missing(&self, other: &Series) -> bool {
#[cfg(feature = "timezones")]
{
use crate::datatypes::DataType::Datetime;

if let Datetime(_, tz_lhs) = self.dtype() {
if let Datetime(_, tz_rhs) = other.dtype() {
if tz_lhs != tz_rhs {
return false;
}
} else {
return false;
}
}
}

// differences from Partial::eq in that numerical dtype may be different
self.len() == other.len()
&& self.name() == other.name()
Expand Down
7 changes: 5 additions & 2 deletions py-polars/tests/unit/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,11 @@ def test_timezone() -> None:
# with pytest.warns(Warning):
tz_s: pl.Series = pl.from_arrow(tz_data) # type: ignore[assignment]

# timezones have no effect, i.e. `s` equals `tz_s`
assert not s.series_equal(tz_s)
# different timezones are not considered equal
# we check both `null_equal=True` and `null_equal=False`
# https://github.com/pola-rs/polars/issues/5023
assert not s.series_equal(tz_s, null_equal=False)
assert not s.series_equal(tz_s, null_equal=True)
assert s.cast(int).series_equal(tz_s.cast(int))


Expand Down

0 comments on commit fb716e1

Please sign in to comment.