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

Reduction ds.by() with one category now fails on 0.15.0 #1230

Closed
desean1625 opened this issue Jun 8, 2023 · 1 comment · Fixed by #1231
Closed

Reduction ds.by() with one category now fails on 0.15.0 #1230

desean1625 opened this issue Jun 8, 2023 · 1 comment · Fixed by #1231
Assignees

Comments

@desean1625
Copy link

The below code worked on 0.14.2 and on 0.15.0 it doesn't get the correct dshape in the category_codes reducer. It wasn't obvious to me why adding a second category "fixed it"

NotImplementedError: Unexpected dshape <function dshape at 0x7f0dfed1da20>

import pandas as pd
import numpy as np
from collections import OrderedDict as odict
import datashader as ds
num=100
np.random.seed(1)

dists = {cat: pd.DataFrame(odict([('x',np.random.normal(x,s,num)), 
                                  ('y',np.random.normal(y,s,num)), 
                                  ('c',np.random.randint(0,val,num)), 
                                  ('t',cat)]))      
         for x,  y,  s,  val, cat in 
         [(  2,  2, 0.03, 10, "d1")] }

df = pd.concat(dists,ignore_index=True)
categories = ['d1']
cat_dtype = pd.api.types.CategoricalDtype(categories=categories, ordered=True)
df["t"] = df["t"].astype(cat_dtype)

agg = ds.Canvas(
    plot_height=256, 
    plot_width=256, 
    x_range=(-8,8),
    y_range=(-8,8)
    ).points(df, "x", "y", agg=ds.by("t", ds.sum("c")))

a "fix" is to add a second category if the length is 1

categories=['d1']
if len(categories) == 1:
  categories.append('')
@desean1625 desean1625 changed the title Reduction by with one category now fails on 0.15.0 Reduction ds.by() with one category now fails on 0.15.0 Jun 8, 2023
@ianthomas23
Copy link
Member

Thanks for the report @desean1625. Evidently we don't have any tests for reductions using a single category.

Problem was caused by #1142. There will be a fix shortly.

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 a pull request may close this issue.

2 participants