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

Remove all use of OrderedDict #1242

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions datashader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import dask.dataframe as dd
import dask.array as da
from xarray import DataArray, Dataset
from collections import OrderedDict

from .utils import Dispatcher, ngjit, calc_res, calc_bbox, orient_array, \
dshape_from_xarray_dataset
Expand Down Expand Up @@ -1304,7 +1303,7 @@ def _cols_to_keep(columns, glyph, agg):
Return which columns from the supplied data source are kept as they are
needed by the specified agg. Excludes any SpecialColumn.
"""
cols_to_keep = OrderedDict({col: False for col in columns})
cols_to_keep = dict({col: False for col in columns})
for col in glyph.required_columns():
cols_to_keep[col] = True

Expand Down
3 changes: 1 addition & 2 deletions datashader/data_libraries/dask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from collections import OrderedDict
import numpy as np
import pandas as pd
import dask
Expand Down Expand Up @@ -58,7 +57,7 @@ def shape_bounds_st_and_axis(df, canvas, glyph):

x_axis = canvas.x_axis.compute_index(x_st, width)
y_axis = canvas.y_axis.compute_index(y_st, height)
axis = OrderedDict([(glyph.x_label, x_axis), (glyph.y_label, y_axis)])
axis = dict([(glyph.x_label, x_axis), (glyph.y_label, y_axis)])

return shape, bounds, st, axis

Expand Down
7 changes: 3 additions & 4 deletions datashader/data_libraries/dask_xarray.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import OrderedDict
from datashader.compiler import compile_components
from datashader.utils import Dispatcher
from datashader.glyphs.quadmesh import (
Expand Down Expand Up @@ -50,7 +49,7 @@ def shape_bounds_st_and_axis(xr_ds, canvas, glyph):

x_axis = canvas.x_axis.compute_index(x_st, width)
y_axis = canvas.y_axis.compute_index(y_st, height)
axis = OrderedDict([(glyph.x_label, x_axis), (glyph.y_label, y_axis)])
axis = dict([(glyph.x_label, x_axis), (glyph.y_label, y_axis)])

return shape, bounds, st, axis

Expand Down Expand Up @@ -99,7 +98,7 @@ def chunk(np_arr, *inds):
)
chunk_coords_list.append([coord_name, coords[coord_name][coord_slice]])

chunk_coords = OrderedDict(chunk_coords_list)
chunk_coords = dict(chunk_coords_list)
chunk_ds = xr.DataArray(
np_arr, coords=chunk_coords, dims=coord_dims, name=var_name
).to_dataset()
Expand Down Expand Up @@ -197,7 +196,7 @@ def chunk(np_arr, *inds):
)
chunk_coords_list.append([coord_name, coords[coord_name][coord_slice]])

chunk_coords = OrderedDict(chunk_coords_list)
chunk_coords = dict(chunk_coords_list)
chunk_ds = xr.DataArray(
np_arr, coords=chunk_coords, dims=coord_dims, name=var_name
).to_dataset()
Expand Down
5 changes: 2 additions & 3 deletions datashader/data_libraries/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from datashader.glyphs.points import _PointLike, _GeometryLike
from datashader.glyphs.area import _AreaToLineLike
from datashader.utils import Dispatcher
from collections import OrderedDict

__all__ = ()

Expand Down Expand Up @@ -49,7 +48,7 @@ def default(glyph, source, schema, canvas, summary, *, antialias=False, cuda=Fal

return finalize(bases,
cuda=cuda,
coords=OrderedDict([(glyph.x_label, x_axis),
(glyph.y_label, y_axis)]),
coords=dict([(glyph.x_label, x_axis),
(glyph.y_label, y_axis)]),
dims=[glyph.y_label, glyph.x_label],
attrs=dict(x_range=x_range, y_range=y_range))
3 changes: 1 addition & 2 deletions datashader/mpl_ext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import OrderedDict
import warnings

from matplotlib.image import _ImageBase
Expand Down Expand Up @@ -32,7 +31,7 @@ def to_ds_image(binned, rgba):
return tf.Image(
uint8_to_uint32(rgba),
dims=binned.dims[:-1],
coords=OrderedDict(
coords=dict(
[
(binned.dims[1], binned.coords[binned.dims[1]]),
(binned.dims[0], binned.coords[binned.dims[0]]),
Expand Down
9 changes: 4 additions & 5 deletions datashader/tests/test_quadmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import xarray as xr
import datashader as ds
import pytest
from collections import OrderedDict

import dask.array
from datashader.tests.test_pandas import assert_eq_ndarray, assert_eq_xr
Expand Down Expand Up @@ -557,7 +556,7 @@ def test_curve_quadmesh_autorange(array_module):
[2., 2., nan, nan],
[2., nan, nan, nan]]
),
coords=OrderedDict([
coords=dict([
('Qx', x_coords),
('Qy', y_coords)]),
dims=['Qy', 'Qx']
Expand Down Expand Up @@ -606,7 +605,7 @@ def test_curve_quadmesh_autorange_chunked():
[2., 2., nan, nan],
[2., nan, nan, nan]]
),
coords=OrderedDict([
coords=dict([
('Qx', x_coords),
('Qy', y_coords)]),
dims=['Qy', 'Qx']
Expand Down Expand Up @@ -657,7 +656,7 @@ def test_curve_quadmesh_manual_range(array_module):
[2., 2., 3., 3.],
[2., 2., 3., 3.]]
),
coords=OrderedDict([
coords=dict([
('Qx', x_coords),
('Qy', y_coords)]),
dims=['Qy', 'Qx']
Expand Down Expand Up @@ -706,7 +705,7 @@ def test_curve_quadmesh_manual_range_subpixel(array_module):
[nan, nan, nan],
[nan, nan, nan]]
),
coords=OrderedDict([
coords=dict([
('Qx', x_coords),
('Qy', y_coords)]),
dims=['Qy', 'Qx']
Expand Down
3 changes: 1 addition & 2 deletions datashader/tests/test_transfer_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import dask.array as da
import PIL
import pytest
from collections import OrderedDict
import datashader.transfer_functions as tf
from datashader.tests.test_pandas import assert_eq_ndarray, assert_eq_xr

coords = OrderedDict([('x_axis', [3, 4, 5]), ('y_axis', [0, 1, 2])])
coords = dict([('x_axis', [3, 4, 5]), ('y_axis', [0, 1, 2])])
dims = ['y_axis', 'x_axis']

# CPU
Expand Down
5 changes: 2 additions & 3 deletions datashader/transfer_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from collections.abc import Iterator

from collections import OrderedDict
from io import BytesIO

import warnings
Expand Down Expand Up @@ -356,7 +355,7 @@ def _colorize(agg, color_key, how, alpha, span, min_alpha, name, color_baseline,
cats = agg.indexes[agg.dims[-1]]
if not len(cats): # No categories and therefore no data; return an empty image
return Image(np.zeros(agg.shape[0:2], dtype=np.uint32), dims=agg.dims[:-1],
coords=OrderedDict([
coords=dict([
(agg.dims[1], agg.coords[agg.dims[1]]),
(agg.dims[0], agg.coords[agg.dims[0]]) ]), name=name)

Expand Down Expand Up @@ -427,7 +426,7 @@ def _colorize(agg, color_key, how, alpha, span, min_alpha, name, color_baseline,

return Image(values,
dims=agg.dims[:-1],
coords=OrderedDict([
coords=dict([
(agg.dims[1], agg.coords[agg.dims[1]]),
(agg.dims[0], agg.coords[agg.dims[0]]),
]),
Expand Down
9 changes: 4 additions & 5 deletions examples/filetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from datashader.utils import export_image
from datashader import transfer_functions as tf
from collections import OrderedDict as odict

#from multiprocessing.pool import ThreadPool
#dask.set_options(pool=ThreadPool(3)) # select a pecific number of threads
Expand Down Expand Up @@ -51,7 +50,7 @@ class Parameters(object):
filetypes_storing_categories = {'parq'}


class Kwargs(odict):
class Kwargs(dict):
"""Used to distinguish between dictionary argument values, and
keyword-arguments.
"""
Expand Down Expand Up @@ -82,7 +81,7 @@ def benchmark(fn, args, filetype=None):
# If we're loading data
if filetype is not None:
if filetype not in filetypes_storing_categories:
opts=odict()
opts = dict()
if p.dftype == 'pandas':
opts['copy']=False
for c in p.categories:
Expand All @@ -107,7 +106,7 @@ def benchmark(fn, args, filetype=None):



read = odict([(f,odict()) for f in ["parq","snappy.parq","gz.parq","feather","h5","csv"]])
read = dict([(f, dict()) for f in ["parq","snappy.parq","gz.parq","feather","h5","csv"]])

def read_csv_dask(filepath, usecols=None):
# Pandas writes CSV files out as a single file
Expand Down Expand Up @@ -143,7 +142,7 @@ def read_parq_pandas(filepath):
read["snappy.parq"] ["pandas"] = lambda filepath,p,filetype: benchmark(read_parq_pandas, (filepath,), filetype)


write = odict([(f,odict()) for f in ["parq","snappy.parq","gz.parq","feather","h5","csv"]])
write = dict([(f, dict()) for f in ["parq","snappy.parq","gz.parq","feather","h5","csv"]])

write["csv"] ["dask"] = lambda df,filepath,p: benchmark(df.to_csv, (filepath.replace(".csv","*.csv"), Kwargs(index=False)))
write["h5"] ["dask"] = lambda df,filepath,p: benchmark(df.to_hdf, (filepath, p.base))
Expand Down
9 changes: 4 additions & 5 deletions examples/getting_started/2_Pipeline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from collections import OrderedDict as odict\n",
"\n",
"num=10000\n",
"np.random.seed(1)\n",
"\n",
"dists = {cat: pd.DataFrame(odict([('x',np.random.normal(x,s,num)), \n",
" ('y',np.random.normal(y,s,num)), \n",
" ('val',val), \n",
" ('cat',cat)])) \n",
"dists = {cat: pd.DataFrame(dict([('x',np.random.normal(x,s,num)), \n",
" ('y',np.random.normal(y,s,num)), \n",
" ('val',val), \n",
" ('cat',cat)])) \n",
" for x, y, s, val, cat in \n",
" [( 2, 2, 0.03, 10, \"d1\"), \n",
" ( 2, -2, 0.10, 20, \"d2\"), \n",
Expand Down
9 changes: 4 additions & 5 deletions examples/getting_started/3_Interactivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@
"import numpy as np\n",
"import datashader as ds\n",
"import datashader.transfer_functions as tf\n",
"from collections import OrderedDict as odict\n",
"\n",
"num=100000\n",
"np.random.seed(1)\n",
"\n",
"dists = {cat: pd.DataFrame(odict([('x',np.random.normal(x,s,num)), \n",
" ('y',np.random.normal(y,s,num)), \n",
" ('val',val), \n",
" ('cat',cat)])) \n",
"dists = {cat: pd.DataFrame(dict([('x',np.random.normal(x,s,num)), \n",
" ('y',np.random.normal(y,s,num)), \n",
" ('val',val), \n",
" ('cat',cat)])) \n",
" for x, y, s, val, cat in \n",
" [( 2, 2, 0.03, 10, \"d1\"), \n",
" ( 2, -2, 0.10, 20, \"d2\"), \n",
Expand Down
5 changes: 2 additions & 3 deletions examples/user_guide/3_Timeseries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"import numpy as np\n",
"import xarray as xr\n",
"import datashader as ds\n",
"import datashader.transfer_functions as tf\n",
"from collections import OrderedDict"
"import datashader.transfer_functions as tf"
]
},
{
Expand Down Expand Up @@ -121,7 +120,7 @@
"source": [
"%%time\n",
"cvs = ds.Canvas(x_range=x_range, y_range=y_range, plot_height=300, plot_width=900)\n",
"aggs= OrderedDict((c, cvs.line(df, 'ITime', c)) for c in cols)\n",
"aggs= dict((c, cvs.line(df, 'ITime', c)) for c in cols)\n",
"img = tf.shade(aggs['a'])"
]
},
Expand Down