vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.39k stars 795 forks source link

chore: use more robust dtype comparisons, use Narwhals stable API in tests #3670

Closed MarcoGorelli closed 2 weeks ago

MarcoGorelli commented 2 weeks ago

Since Narwhals 1.9.0 (release last month), nw.Datetime has time_unit and time_zone metadata, which means that hash(nw.Datetime) has changed. This change only affects the main Narwhals namespace - the narwhals.stable.v1 namespace (which you're using 🙌 ) is unaffected

The fact that having narwhals.stable.v1 allowed us to make this change without it affecting any users is a pretty good feeling 😄

I've rewritten the dtype comparison from

elif dtype in {nw.Datetime, nw.Date}:

to

elif dtype == nw.Datetime or dtype == nw.Date:

so that it will also work in the same way if and when you decide to move to narwhals.stable.v2 (when we get there). There'll be no obligation to perform such a move of course, we'll keep stable.v1 working as-is, so either way, there's no impact on users


See the second bullet point at https://narwhals-dev.github.io/narwhals/backcompat/#after-stablev1 for more context