8000 Fix patching table with `pd.Timestamp` values by maximlt · Pull Request #5650 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix patching pd.Timestamp values
  • Loading branch information
maximlt committed Oct 16, 2023
commit ed74056b0decf83db5fa6b40ff936ad5d1d952d5
23 changes: 23 additions & 0 deletions panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,29 @@ def test_tabulator_patch_ranges(document, comm):
if col != 'index':
np.testing.assert_array_equal(table.value[col].values, expected[col])

def test_tabulator_patch_with_timestamp(document, comm):
# https://github.com/holoviz/panel/issues/5555
df = pd.DataFrame(dict(A=pd.to_datetime(['1980-01-01', '1980-01-02'])))
table = Tabulator(df)

model = table.get_root(document, comm)

table.patch({'A': [(0, pd.Timestamp('2021-01-01'))]})

expected = {
'index': np.array([0, 1]),
'A': np.array(['2021-01-01T00:00:00.000000000',
'1980-01-02T00:00:00.000000000'],
dtype='datetime64[ns]')
}
for col, values in model.source.data.items():
if col == 'A':
expected_array = expected[col].astype(np.int64) / 10e5
else:
expected_array = expected[col]
np.testing.assert_array_equal(values, expected_array)
if col != 'index':
np.testing.assert_array_equal(table.value[col].values, expected[col])

def test_tabulator_stream_series_paginated_not_follow(document, comm):
df = makeMixedDataFrame()
Expand Down
4 changes: 3 additions & 1 deletion panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from ..io.state import state
from ..reactive import Reactive, ReactiveData
from ..util import (
clone_model, isdatetime, lazy_load, updating,
clone_model, datetime_as_utctimestamp, isdatetime, lazy_load, updating,
)
from .base import Widget
from .button import Button
Expand Down Expand Up @@ -822,6 +822,8 @@ def patch(self, patch_value, as_index=True):
self.value.loc[data_ind, k] = value
else:
self.value.iloc[data_ind, columns.index(k)] = value
if isinstance(value, pd.Timestamp):
value = datetime_as_utctimestamp(value)
values.append((patch_ind, value))
patches[k] = values
self._patch(patches)
Expand Down
0