We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Sorting Footguns

Both Pandas and Polars sort in ascending order by default... but the parameters are named in opposite ways.

Pandas' sort_values() method has an ascending parameter that's True by default. Polars' sort() method has a descending parameter that's False by default. Don't mix them up.

Sort Nulls and NaNs

Polars generally refers to missing values as nulls. It can also contain floating-point NaN values, but null and NaN are different things in Polars.

Pandas is looser with its terminology. You'll see "missing values," "NA values," "nulls," and NaNs used around missing data.

The trickiest footgun here is that, by default, Pandas' sort_values() places missing values at the end of the sorted output, while Polars' sort() places null values at the beginning. This is a common source of bugs when migrating between libraries!

Both libraries let you control this behavior, but the default is different.

  • Pandas default: sort_values(..., na_position="last")
  • Polars default: sort(..., nulls_last=False)

To make Polars match Pandas' default, use sort(..., nulls_last=True).

Assignment

The SnackStack support team reviews devices that have gone quiet. Devices that have been offline the longest should appear first, but unknown offline times should not jump to the top of the queue.

Complete the build_offline_review_queue function. It accepts a Polars DataFrame of device status rows and returns a new DataFrame for review.