Error while predicting, shape of passed values is (1,130), indices imply (1, 127)

Hello everyone,

I’m using a model deployed into production and i’m running into this issue when i call the function learn.predict(). The model is a TabularLearner that works fine in my Jupyter environment so I assume i’m doing something wrong in production, but i can’t get my finger on it.

This is the stack trace:
Traceback (most recent call last):
File “/project/venv/lib/python3.8/site-packages/fastai/tabular/”, line 333, in decodes
try: df = pd.DataFrame(vals,
File “/project/venv/lib/python3.8/site-packages/fastcore/”, line 153, in getattr
if attr is not None: return getattr(attr,k)
File “/project/venv/lib/python3.8/site-packages/fastcore/”, line 202, in getattr
def getattr(self,k): return gather_attrs(self, k, ‘fs’)
File “/project/venv/lib/python3.8/site-packages/fastcore/”, line 165, in gather_attrs
if not res: raise AttributeError(k)
AttributeError: all_col_names

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/project/venv/lib/python3.8/site-packages/pandas/core/internals/", line 1654, in create_block_manager_from_blocks
    make_block(values=blocks[0], placement=slice(0, len(axes[0])))
  File "/project/venv/lib/python3.8/site-packages/pandas/core/internals/", line 3049, in make_block
    return klass(values, ndim=ndim, placement=placement)
  File "/project/venv/lib/python3.8/site-packages/pandas/core/internals/", line 124, in __init__
    raise ValueError(
ValueError: Wrong number of items passed 130, placement implies 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 366, in <module>
  File "/project/venv/lib/python3.8/site-packages/fastai/tabular/", line 21, in predict
    full_dec = self.dls.decode(b)
  File "/project/venv/lib/python3.8/site-packages/fastai/data/", line 80, in decode
    def decode(self, b): return self.before_batch.decode(to_cpu(self.after_batch.decode(self._retain_dl(b))))
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 206, in decode
    if full: return compose_tfms(o, tfms=self.fs, is_enc=False, reverse=True, split_idx=self.split_idx)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 150, in compose_tfms
    x = f(x, **kwargs)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 114, in decode
    def decode(self, x, **kwargs):   return self._call1(x, 'decode', **kwargs)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 117, in _call1
    y = getattr(super(), name)(list(x), **kwargs)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 74, in decode
    def decode  (self, x, **kwargs): return self._call('decodes', x, **kwargs)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 83, in _call
    return self._do_call(getattr(self, fn), x, **kwargs)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 89, in _do_call
    return retain_type(f(x, **kwargs), x, ret)
  File "/project/venv/lib/python3.8/site-packages/fastcore/", line 112, in __call__
    return f(*args, **kwargs)
  File "/project/venv/lib/python3.8/site-packages/fastai/tabular/", line 334, in decodes
    except: df = pd.DataFrame(vals,
  File "/project/venv/lib/python3.8/site-packages/fastai/", line 466, in __init__
    self._old_init(data, index=index, columns=columns, dtype=dtype, copy=copy)
  File "/project/venv/lib/python3.8/site-packages/pandas/core/", line 464, in __init__
    mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
  File "/project/venv/lib/python3.8/site-packages/pandas/core/internals/", line 210, in init_ndarray
    return create_block_manager_from_blocks(block_values, [columns, index])
  File "/project/venv/lib/python3.8/site-packages/pandas/core/internals/", line 1664, in create_block_manager_from_blocks
    construction_error(tot_items, blocks[0].shape[1:], axes, e)
  File "/project/venv/lib/python3.8/site-packages/pandas/core/internals/", line 1694, in construction_error
    raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
ValueError: Shape of passed values is (1, 130), indices imply (1, 127)

So far i’ve worked around this problem by modifying the predict function in the TabularLearner class, (Commeting the line that caused the issue and modifying the return to just yield dec_preds and preds) but this is obviously not and ideal solution and i was hoping to find some help here.

Thanks everyone!

How many cat and cont variables do you have in your dataset?

107 cont variables and 20 cat variables if i remember correctly.

Thanks for replying!

I’ve been doing some tinkering and I managed to fix the issue by updating my pandas version from 1.0.4 to 1.1.0. Just wanted to share it in case this happens to someone else.

@muellerzr, don’t know if you looked into it but the problem appears to be fixed, thanks anyway! :smiley:

1 Like