Skip to content

Commit

Permalink
Update to work with pandas 2.2 (#6259)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Jan 23, 2024
1 parent 21dfdb9 commit 075b5ae
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 87 deletions.
2 changes: 1 addition & 1 deletion doc/how_to/param/uis.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Example(BaseClass):
color = param.Color(default='#FFFFFF')
date = param.Date(default=dt.datetime(2017, 1, 1),
bounds=(dt.datetime(2017, 1, 1), dt.datetime(2017, 2, 1)))
dataframe = param.DataFrame(default=pd._testing.makeDataFrame().iloc[:3])
dataframe = param.DataFrame(default=pd.DataFrame({'A': [1, 2, 3]}))
select_string = param.ObjectSelector(default="yellow", objects=["red", "yellow", "green"])
select_fn = param.ObjectSelector(default=list,objects=[list, set, dict])
int_list = param.ListSelector(default=[3, 5], objects=[1, 3, 5, 7, 9], precedence=0.5)
Expand Down
7 changes: 6 additions & 1 deletion examples/reference/panes/DataFrame.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
"metadata": {},
"outputs": [],
"source": [
"df = pd._testing.makeMixedDataFrame()\n",
"df = pd.DataFrame({\n",
" 'int': [1, 2, 3],\n",
" 'float': [3.14, 6.28, 9.42],\n",
" 'str': ['A', 'B', 'C'],\n",
" 'bool': [True, False, True],\n",
"}, index=[1, 2, 3])\n",
"\n",
"df_pane = pn.pane.DataFrame(df, width=400)\n",
"\n",
Expand Down
76 changes: 27 additions & 49 deletions examples/reference/widgets/DataFrame.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"import datetime as dt\n",
"import pandas as pd\n",
"import panel as pn\n",
"\n",
Expand Down Expand Up @@ -83,12 +82,17 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame({'int': [1, 2, 3], 'float': [3.14, 6.28, 9.42], 'str': ['A', 'B', 'C'], 'bool': [True, False, True]}, index=[1, 2, 3])\n",
"df = pd.DataFrame({\n",
" 'int': [1, 2, 3],\n",
" 'float': [3.14, 6.28, 9.42],\n",
" 'str': ['A', 'B', 'C'],\n",
" 'bool': [True, False, True],\n",
" 'date': [dt.date(2019, 1, 1), dt.date(2020, 1, 1), dt.date(2020, 1, 10)],\n",
" 'datetime': [dt.datetime(2019, 1, 1, 10), dt.datetime(2020, 1, 1, 12), dt.datetime(2020, 1, 10, 13)]\n",
"}, index=[1, 2, 3])\n",
"\n",
"df_widget = pn.widgets.DataFrame(df, name='DataFrame')\n",
"\n",
Expand All @@ -105,9 +109,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"from bokeh.models.widgets.tables import SelectEditor, NumberFormatter\n",
Expand All @@ -129,9 +131,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"table.selection = [0, 2]\n",
Expand All @@ -155,14 +155,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"custom_df = pd._testing.makeMixedDataFrame()\n",
"\n",
"pn.widgets.DataFrame(custom_df, autosize_mode='none', widths={'index': 50, 'A': 50, 'B': 50, 'C': 70, 'D': 130}, width=350)"
"pn.widgets.DataFrame(df, autosize_mode='none', widths={'index': 50, 'int': 50, 'float': 50, 'str': 70, 'bool': 130}, width=350)"
]
},
{
Expand All @@ -177,12 +173,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.DataFrame(custom_df, autosize_mode='fit_columns', width=300)"
"pn.widgets.DataFrame(df, autosize_mode='fit_columns', width=300)"
]
},
{
Expand All @@ -197,12 +191,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.DataFrame(custom_df, autosize_mode='fit_viewport')"
"pn.widgets.DataFrame(df, autosize_mode='fit_viewport')"
]
},
{
Expand All @@ -221,12 +213,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"date_df = pd._testing.makeTimeDataFrame()\n",
"date_df = df.set_index('datetime').iloc[:5, :2]\n",
"\n",
"pn.widgets.DataFrame(date_df, height=400, widths=150, frozen_columns=1, autosize_mode='none')"
]
Expand All @@ -243,9 +233,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"agg_df = pd.concat([date_df, date_df.median().to_frame('Median').T, date_df.mean().to_frame('Mean').T])\n",
Expand All @@ -268,9 +256,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"from bokeh.sampledata.population import data as population_data \n",
Expand All @@ -292,9 +278,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
Expand All @@ -315,9 +299,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"def stream_data():\n",
Expand All @@ -339,9 +321,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"patch_table = pn.widgets.DataFrame(df[['int', 'float', 'str', 'bool']])\n",
Expand All @@ -368,9 +348,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"patch_table.patch({\n",
Expand Down
28 changes: 12 additions & 16 deletions examples/reference/widgets/Tabulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"metadata": {},
"outputs": [],
"source": [
"custom_df = pd._testing.makeMixedDataFrame().iloc[:3, :]\n",
"custom_df = df.iloc[:3, :]\n",
"\n",
"pn.widgets.Tabulator(custom_df, widths={'index': 70, 'A': 50, 'B': 50, 'C': 70, 'D': 130})"
]
Expand Down Expand Up @@ -632,9 +632,7 @@
"metadata": {},
"outputs": [],
"source": [
"wide_df = pd._testing.makeCustomDataframe(3, 10, r_idx_names=['index'])\n",
"\n",
"pn.widgets.Tabulator(wide_df, frozen_columns=['index'], width=400)"
"pn.widgets.Tabulator(df, frozen_columns=['index'], width=400)"
]
},
{
Expand All @@ -652,7 +650,7 @@
"metadata": {},
"outputs": [],
"source": [
"date_df = pd._testing.makeTimeDataFrame().iloc[:5, :2]\n",
"date_df = df.set_index('date').iloc[:5, :2]\n",
"agg_df = pd.concat([date_df, date_df.median().to_frame('Median').T, date_df.mean().to_frame('Mean').T])\n",
"agg_df.index= agg_df.index.map(str)\n",
"\n",
Expand Down Expand Up @@ -788,7 +786,7 @@
"metadata": {},
"outputs": [],
"source": [
"large_df = pd._testing.makeCustomDataframe(100000, 5)\n",
"large_df = pd.DataFrame({'A': np.random.rand(10000)})\n",
"pn.widgets.Tabulator(large_df, pagination='remote', page_size=3)"
]
},
Expand All @@ -805,7 +803,7 @@
"metadata": {},
"outputs": [],
"source": [
"medium_df = pd._testing.makeCustomDataframe(1000, 5)\n",
"medium_df = pd.DataFrame({'A': np.random.rand(1000)})\n",
"pn.widgets.Tabulator(medium_df, pagination='local', page_size=3)"
]
},
Expand Down Expand Up @@ -834,7 +832,7 @@
"metadata": {},
"outputs": [],
"source": [
"filter_table = pn.widgets.Tabulator(pd._testing.makeMixedDataFrame())\n",
"filter_table = pn.widgets.Tabulator(df)\n",
"filter_table"
]
},
Expand All @@ -851,7 +849,7 @@
"metadata": {},
"outputs": [],
"source": [
"filter_table.add_filter((0, 3), 'A')"
"filter_table.add_filter((1, 2), 'int')"
]
},
{
Expand All @@ -868,7 +866,7 @@
"outputs": [],
"source": [
"slider = pn.widgets.RangeSlider(start=0, end=3, name='A Filter')\n",
"filter_table.add_filter(slider, 'A')"
"filter_table.add_filter(slider, 'int')"
]
},
{
Expand All @@ -884,8 +882,8 @@
"metadata": {},
"outputs": [],
"source": [
"select = pn.widgets.MultiSelect(options=['foo1', 'foo2', 'foo3', 'foo4', 'foo5'], name='C Filter')\n",
"filter_table.add_filter(select, 'C')"
"select = pn.widgets.MultiSelect(options=list('ABC'), name='str Filter')\n",
"filter_table.add_filter(select, 'str')"
]
},
{
Expand Down Expand Up @@ -920,7 +918,7 @@
"metadata": {},
"outputs": [],
"source": [
"select.value = ['foo1', 'foo2']\n",
"select.value = ['A', 'B']\n",
"filter_table.current_view"
]
},
Expand Down Expand Up @@ -1033,9 +1031,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"metadata": {},
"outputs": [],
"source": [
"movie_filters = {\n",
Expand Down
10 changes: 8 additions & 2 deletions panel/tests/io/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,19 @@ def test_ndarray_hash():
)

def test_dataframe_hash():
df1, df2 = pd._testing.makeMixedDataFrame(), pd._testing.makeMixedDataFrame()
data = {
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
"D": pd.bdate_range("1/1/2009", periods=5),
}
df1, df2 = pd.DataFrame(data), pd.DataFrame(data)
assert hashes_equal(df1, df2)
df2['A'] = df2['A'].values[::-1]
assert not hashes_equal(df1, df2)

def test_series_hash():
series1 = pd._testing.makeStringSeries()
series1 = pd.Series([0.0, 1.0, 2.0, 3.0, 4.0])
series2 = series1.copy()
assert hashes_equal(series1, series2)
series2.iloc[0] = 3.14
Expand Down
10 changes: 5 additions & 5 deletions panel/tests/pane/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def test_get_markdown_pane_type():
assert PaneBase.get_pane_type("**Markdown**") is Markdown

def test_get_dataframe_pane_type():
df = pd._testing.makeDataFrame()
df = pd.DataFrame({"A": [1, 2, 3]})
assert PaneBase.get_pane_type(df) is DataFrame

def test_get_series_pane_type():
df = pd._testing.makeDataFrame()
assert PaneBase.get_pane_type(df.iloc[:, 0]) is DataFrame
ser = pd.Series([1, 2, 3])
assert PaneBase.get_pane_type(ser) is DataFrame

@streamz_available
def test_get_streamz_dataframe_pane_type():
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_html_pane_sanitize_html(document, comm):
assert model.text.endswith('<h1><strong>HTML</h1></strong>')

def test_dataframe_pane_pandas(document, comm):
pane = DataFrame(pd._testing.makeDataFrame())
pane = DataFrame(pd.DataFrame({"A": [1, 2, 3]}))

# Create pane
model = pane.get_root(document, comm=comm)
Expand All @@ -176,7 +176,7 @@ def test_dataframe_pane_pandas(document, comm):
orig_text = model.text

# Replace Pane.object
pane.object = pd._testing.makeMixedDataFrame()
pane.object = pd.DataFrame({"B": [1, 2, 3]})
assert pane._models[model.ref['id']][0] is model
assert model.text.startswith('<table')
assert model.text != orig_text
Expand Down
2 changes: 1 addition & 1 deletion panel/tests/ui/io/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
tabulator_app = """
import panel as pn
import pandas as pd
tabulator = pn.widgets.Tabulator(pd._testing.makeMixedDataFrame())
tabulator = pn.widgets.Tabulator(pd.DataFrame({'a': [1, 2, 3]}))
def on_click(e):
tabulator.theme = 'fast'
Expand Down
Loading

0 comments on commit 075b5ae

Please sign in to comment.