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

Add Pandas 2.0 support #5662

Merged
merged 37 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9d0a637
Cast to datetime64[ns]
hoxbro Mar 14, 2023
28315f5
Update test
hoxbro Mar 14, 2023
ea13012
Add to github actions
hoxbro Mar 14, 2023
1b94895
Add astype
hoxbro Mar 14, 2023
ddc9c77
Add comment
hoxbro Mar 14, 2023
ad5a888
Ignore not supported Dask test yet
hoxbro Mar 14, 2023
1cd2692
Update ci
hoxbro Mar 14, 2023
5ba1915
Test
hoxbro Mar 14, 2023
4477f31
Update examples with keyword argument
hoxbro Mar 14, 2023
0f2b1d7
Fix connect_tri_edges_pd
hoxbro Mar 14, 2023
22fa6f8
Add rest of keywords arguments
hoxbro Mar 14, 2023
c7f3db4
Merge branch 'main' into pandas_2
hoxbro Apr 4, 2023
189a115
Always convert to datetime64[ns]
hoxbro Apr 4, 2023
78a9001
Update test.yaml
hoxbro Apr 4, 2023
5498e5f
Force dt_to_int to return int
hoxbro Apr 4, 2023
30b0788
Only copy if xtype/ytype is datetime
hoxbro Apr 4, 2023
c35c112
Add spatialpandas to bokeh2 only test
hoxbro Apr 4, 2023
f3c800d
Add fix for np.intc pandas
hoxbro Apr 6, 2023
a819fa4
Workaround xarray not supporting pandas 2.0 yet
hoxbro Apr 6, 2023
55ec5dd
Remove rc for unittest
hoxbro Apr 8, 2023
131b90b
Add os to test.yaml
hoxbro Apr 8, 2023
3f94aaa
Add rest of os
hoxbro Apr 8, 2023
287680e
Don't run examples on pandas=2.0 because of xarray incompatibility
hoxbro Apr 8, 2023
a896898
Add ignore_glob to file
hoxbro Apr 8, 2023
f17f33e
Remove version 3.11 safe guard for examples
hoxbro Apr 8, 2023
3ae3385
Add more notebooks to ignore
hoxbro Apr 8, 2023
77ed9af
Better path in conftest
hoxbro Apr 8, 2023
3d5bfe6
Ignore xarray examples for pandas 2
hoxbro Apr 8, 2023
c455113
Only ignore pandas bug on windows
hoxbro Apr 8, 2023
801dd8f
Try again with pandas two as default
hoxbro Apr 19, 2023
e7fb207
Remove pandas pin
hoxbro Apr 19, 2023
10dbd1c
Merge branch 'main' into pandas_2
hoxbro Apr 19, 2023
c0c0c22
Remove Bokeh dev channel
hoxbro Apr 19, 2023
165eae8
Remove pandas 1 from CI
hoxbro Apr 19, 2023
af9e597
Add back xarray examples to CI
hoxbro Apr 19, 2023
b3012d3
Add 15-Large_Data to Pandas2-windows ignore
hoxbro Apr 19, 2023
d2ec764
Clean up
hoxbro Apr 20, 2023
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
19 changes: 16 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: pre-commit
uses: pre-commit/action@v3.0.0
test_suite:
name: Pytest on ${{ matrix.python-version }}, Bokeh ${{ matrix.bokeh-version }}, ${{ matrix.os }}
name: Pytest on ${{ matrix.python-version }}, Bokeh ${{ matrix.bokeh-version }}, Pandas ${{ matrix.pandas-version }}, ${{ matrix.os }}
needs: [pre_commit]
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -37,16 +37,22 @@ jobs:
# Run on the full set on schedule, workflow_dispatch and push&tags events, otherwise on a subset.
python-version: ${{ ( github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || ( github.event_name == 'push' && github.ref_type == 'tag' ) ) && fromJSON('["3.7", "3.8", "3.9", "3.10", "3.11"]') || fromJSON('["3.7", "3.9", "3.11"]') }}
bokeh-version: ['2', '3']
pandas-version: ['1']
exclude:
# Bokeh 3 does not support Python 3.7
- bokeh-version: '3'
python-version: '3.7'
include:
- pandas-version: '2'
bokeh-version: '3'
python-version: '3.10'
os: 'ubuntu-latest'
timeout-minutes: 120 # Because slow conda solve on Python 3.7
defaults:
run:
shell: bash -el {0}
env:
DESC: "Python ${{ matrix.python-version }} - Bokeh ${{ matrix.bokeh-version }} tests"
DESC: "Python ${{ matrix.python-version }} - Bokeh ${{ matrix.bokeh-version }} - Pandas ${{ matrix.pandas-version }} tests"
PYTHON_VERSION: ${{ matrix.python-version }}
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"
DISPLAY: ":99.0"
Expand All @@ -56,7 +62,7 @@ jobs:
steps:
- uses: pyviz-dev/holoviz_tasks/install@v0.1a9
with:
name: unit_test_suite_bokeh${{ matrix.bokeh-version }}
name: unit_test_suite_bokeh${{ matrix.bokeh-version }}_pandas${{ matrix.pandas-version }}
python-version: ${{ matrix.python-version }}
channel-priority: strict
channels: pyviz/label/dev,bokeh/label/dev,conda-forge,nodefaults
Expand All @@ -65,6 +71,13 @@ jobs:
conda-update: true
conda-mamba: mamba
id: install
- name: Pandas 2.0 install
if: steps.install.outputs.cache-hit != 'true' && matrix.pandas-version == '2'
run: |
conda activate test-environment
conda uninstall pandas dask dask-core --force --offline -y
mamba install pandas -c conda-forge/label/pandas_rc -y
mamba install dask-core -y
- name: bokeh sampledata
run: |
conda activate test-environment
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/bars_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', delimiter='\\t')\n",
"key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
"value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
" ('gdp', 'GDP Growth'), ('trade', 'Trade')]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/dropdown_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', delimiter='\\t')\n",
"key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
"value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
" ('gdp', 'GDP Growth'), ('trade', 'Trade')]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/scatter_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', delimiter='\\t')\n",
"key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
"value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
" ('gdp', 'GDP Growth'), ('trade', 'Trade')]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/us_unemployment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"source": [
"from bokeh.sampledata.unemployment1948 import data\n",
"\n",
"data = pd.melt(data.drop('Annual', 1), id_vars='Year', var_name='Month', value_name='Unemployment')\n",
"data = pd.melt(data.drop('Annual', axis=1), id_vars='Year', var_name='Month', value_name='Unemployment')\n",
"heatmap = hv.HeatMap(data, label=\"US Unemployment (1948 - 2013)\")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/bars_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', delimiter='\\t')\n",
"key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
"value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
" ('gdp', 'GDP Growth'), ('trade', 'Trade')]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/dropdown_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', delimiter='\\t')\n",
"key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
"value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
" ('gdp', 'GDP Growth'), ('trade', 'Trade')]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/scatter_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', delimiter='\\t')\n",
"key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
"value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
" ('gdp', 'GDP Growth'), ('trade', 'Trade')]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/us_unemployment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"\n",
"colors = [\"#75968f\", \"#a5bab7\", \"#c9d9d3\", \"#e2e2e2\", \"#dfccce\", \"#ddb7b1\", \"#cc7878\", \"#933b41\", \"#550b1d\"]\n",
"\n",
"data = pd.melt(data.drop('Annual', 1), id_vars='Year', var_name='Month', value_name='Unemployment')\n",
"data = pd.melt(data.drop('Annual', axis=1), id_vars='Year', var_name='Month', value_name='Unemployment')\n",
"\n",
"heatmap = hv.HeatMap(data, label=\"US Unemployment (1948 - 2013)\")"
]
Expand Down
2 changes: 1 addition & 1 deletion holoviews/element/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def connect_tri_edges_pd(trimesh):
edges = edges.drop("color", errors="ignore", axis=1).reset_index()
nodes = trimesh.nodes.dframe().copy()
nodes.index.name = 'node_index'
nodes = nodes.drop("color", errors="ignore", axis=1)
nodes = nodes.drop(["color", "z"], errors="ignore", axis=1)
v1, v2, v3 = trimesh.kdims
x, y, idx = trimesh.nodes.kdims[:3]

Expand Down
12 changes: 6 additions & 6 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def _process(self, element, key=None):
df['y0'] = np.array(0, df.dtypes[y.name])
yagg = ['y0', y.name]
if xtype == 'datetime':
df[x.name] = cast_array_to_int64(df[x.name].astype('datetime64[us]'))
df[x.name] = cast_array_to_int64(df[x.name].astype('datetime64[ns]'))

params = self._get_agg_params(element, x, y, agg_fn, (x0, y0, x1, y1))

Expand Down Expand Up @@ -820,13 +820,13 @@ def _process(self, element, key=None):
(x_range, y_range), (xs, ys), (width, height), (xtype, ytype) = info
((x0, x1), (y0, y1)), (xs, ys) = self._dt_transform(x_range, y_range, xs, ys, xtype, ytype)

df = element.interface.as_dframe(element)
df = element.interface.as_dframe(element).copy()
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
if xtype == 'datetime':
df[x0d.name] = cast_array_to_int64(df[x0d.name].astype('datetime64[us]'))
df[x1d.name] = cast_array_to_int64(df[x1d.name].astype('datetime64[us]'))
df[x0d.name] = cast_array_to_int64(df[x0d.name].astype('datetime64[ns]'))
df[x1d.name] = cast_array_to_int64(df[x1d.name].astype('datetime64[ns]'))
if ytype == 'datetime':
df[y0d.name] = cast_array_to_int64(df[y0d.name].astype('datetime64[us]'))
df[y1d.name] = cast_array_to_int64(df[y1d.name].astype('datetime64[us]'))
df[y0d.name] = cast_array_to_int64(df[y0d.name].astype('datetime64[ns]'))
df[y1d.name] = cast_array_to_int64(df[y1d.name].astype('datetime64[ns]'))

if isinstance(agg_fn, ds.count_cat) and df[agg_fn.column].dtype.name != 'category':
df[agg_fn.column] = df[agg_fn.column].astype('category')
Expand Down
17 changes: 17 additions & 0 deletions holoviews/tests/core/data/test_daskinterface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from unittest import SkipTest
import unittest

import numpy as np
import pandas as pd
from packaging.version import Version

try:
import dask.dataframe as dd
Expand All @@ -10,6 +12,7 @@

from holoviews.core.data import Dataset
from holoviews.util.transform import dim
from holoviews.core.util import pandas_version

from .test_pandasinterface import BasePandasInterfaceTests

Expand Down Expand Up @@ -73,6 +76,20 @@ def test_dataset_2D_partial_reduce_ht(self):
def test_dataset_aggregate_string_types(self):
raise SkipTest("Temporarily skipped")

@unittest.skipIf(
pandas_version >= Version("2.0rc0"),
reason="Not supported yet, https://github.com/dask/dask/issues/9913"
)
def test_dataset_aggregate_ht(self):
super().test_dataset_aggregate_ht()

@unittest.skipIf(
pandas_version >= Version("2.0rc0"),
reason="Not supported yet, https://github.com/dask/dask/issues/9913"
)
def test_dataset_aggregate_ht_alias(self):
super().test_dataset_aggregate_ht_alias()

def test_dataset_from_multi_index(self):
raise SkipTest("Temporarily skipped")
df = pd.DataFrame({'x': np.arange(10), 'y': np.arange(10), 'z': np.random.rand(10)})
Expand Down
4 changes: 1 addition & 3 deletions holoviews/tests/plotting/bokeh/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,8 @@ def test_cds_resolves(self):
self.assertEqual(resolved, {'id': cds.ref['id'],
'value': points.columns()})

@pytest.mark.filterwarnings("ignore::FutureWarning")
def test_rangexy_datetime(self):
# Raises a warning because makeTimeDataFrame isn't part of the public API.
curve = Curve(pd.util.testing.makeTimeDataFrame(), 'index', 'C')
curve = Curve(pd._testing.makeTimeDataFrame(), 'index', 'C')
stream = RangeXY(source=curve)
plot = bokeh_server_renderer.get_plot(curve)
callback = plot.callbacks[0]
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ namespace_map =
ibis-framework=ibis-sqlite
; dask pins to bokeh<3 right now
dask=dask-core
geoviews=geoviews-core