Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabulator: custom datetime sorter #3839

Merged
merged 3 commits into from Sep 15, 2022
Merged

Tabulator: custom datetime sorter #3839

merged 3 commits into from Sep 15, 2022

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Sep 15, 2022

As already pointed out before Tabulator JS defines its own sorters, which can behave differently from df.sort_values. The result of these two sorters was different when applied to datetime columns that contain NaN values (this causes issues with the index of edit/click events returned when the sorters aren't aligned on their result...). Datetime cols are actually serialized as UNIX timestamps by Bokeh, and NaN values to -9223372036854776 (see bokeh/bokeh#10448). Tabulator JS was using its number built-in sorter to sorter this kind of column in the end, the NaN values being first when sorting in an ascending way. The default behavior of df.sort_values is put NaNs at the end (see https://pandas.pydata.org/docs/reference/api/pandas.Series.sort_values.html#pandas.Series.sort_values). This is where the two sorting algorithms were diverging. Pandas' df.sort_values has the na_position parameter that can be set to 'first', except that it applies to all the columns which I didn't want to do that now, as it affects all the dtypes. Instead this PR adds a custom sorter for datetime objects which always puts the NaNs at the end as df.sort_values.

@codecov
Copy link

codecov bot commented Sep 15, 2022

Codecov Report

Merging #3839 (723e9e0) into master (affb9dd) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3839   +/-   ##
=======================================
  Coverage   82.86%   82.87%           
=======================================
  Files         222      222           
  Lines       32413    32421    +8     
=======================================
+ Hits        26860    26868    +8     
  Misses       5553     5553           
Flag Coverage Δ
ui-tests 34.20% <0.00%> (-0.01%) ⬇️
unitexamples-tests 75.24% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
panel/tests/ui/widgets/test_tabulator.py 98.88% <ø> (ø)
panel/tests/widgets/test_tables.py 99.66% <ø> (ø)
panel/widgets/tables.py 88.44% <100.00%> (+0.08%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@philippjfr
Copy link
Member

Ready to merge?

@maximlt
Copy link
Member Author

maximlt commented Sep 15, 2022

Yes

@philippjfr philippjfr merged commit 23b061b into master Sep 15, 2022
@philippjfr philippjfr deleted the tabulator_sorting_date branch September 15, 2022 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants