question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Length of values (1) does not match length of index with sc.pp.calculate_qc_metrics(adata)

See original GitHub issue
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the master branch of scanpy.

I also tried ‘log1p = False’ and produced the other error. Thank you.

sc.pp.calculate_qc_metrics(adata)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/scanpy/preprocessing/_qc.py", line 294, in calculate_qc_metrics
    obs_metrics = describe_obs(
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/scanpy/preprocessing/_qc.py", line 111, in describe_obs
    obs_metrics[f"log1p_total_{expr_type}"] = np.log1p(
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/core/frame.py", line 3612, in __setitem__
    self._set_item(key, value)
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/core/frame.py", line 3784, in _set_item
    value = self._sanitize_column(value)
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/core/frame.py", line 4509, in _sanitize_column
    com.require_length_match(value, self.index)
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/core/common.py", line 531, in require_length_match
    raise ValueError(
ValueError: Length of values (1) does not match length of index (35255)
>

sc.pp.calculate_qc_metrics(adata, log1p = False)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/core/frame.py", line 995, in __repr__
    self.to_string(
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/core/frame.py", line 1131, in to_string
    return fmt.DataFrameRenderer(formatter).to_string(
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1053, in to_string
    string = string_formatter.to_string()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/string.py", line 25, in to_string
    text = self._get_string_representation()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/string.py", line 40, in _get_string_representation
    strcols = self._get_strcols()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/string.py", line 31, in _get_strcols
    strcols = self.fmt.get_strcols()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 540, in get_strcols
    strcols = self._get_strcols_without_index()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 804, in _get_strcols_without_index
    fmt_values = self.format_col(i)
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 818, in format_col
    return format_array(
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1240, in format_array
    return fmt_obj.get_result()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1271, in get_result
    fmt_values = self._format_strings()
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1518, in _format_strings
    return list(self.get_result_as_array())
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1482, in get_result_as_array
    formatted_values = format_values_with(float_format)
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1456, in format_values_with
    values = format_with_na_rep(values, formatter, na_rep)
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1427, in format_with_na_rep
    [
  File "/root/miniconda3/envs/scanpy/lib/python3.9/site-packages/pandas/io/formats/format.py", line 1428, in <listcomp>
    formatter(val) if not m else na_rep
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Versions

WARNING: If you miss a compact list, please try print_header!

anndata 0.7.6 scanpy 1.7.2 sinfo 0.3.1

PIL 8.3.2 anndata 0.7.6 beta_ufunc NA binom_ufunc NA cffi 1.14.6 colorama 0.4.4 concurrent NA cycler 0.10.0 cython_runtime NA dateutil 2.8.2 dunamai 1.6.0 encodings NA genericpath NA get_version 3.5 h5py 3.4.0 joblib 1.0.1 kiwisolver 1.3.2 legacy_api_wrap 0.0.0 llvmlite 0.37.0 matplotlib 3.4.3 mpl_toolkits NA natsort 7.1.1 nbinom_ufunc NA ntpath NA numba 0.54.0 numexpr 2.7.3 numpy 1.20.3 opcode NA packaging 21.0 pandas 1.3.3 pkg_resources NA posixpath NA pycparser 2.20 pyexpat NA pyparsing 2.4.7 pytz 2021.1 scanpy 1.7.2 scipy 1.7.1 setuptools_scm NA sinfo 0.3.1 six 1.16.0 sklearn 1.0 sphinxcontrib NA sre_compile NA sre_constants NA sre_parse NA tables 3.6.1

Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:46) [GCC 9.4.0] Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.31 24 logical CPU cores, x86_64

Session information updated at 2021-10-01 14:56

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
sfortma2commented, Oct 20, 2021

Many thanks for everyone’s input. The bug is indeed due to an issue with Pandas ≥1.3. I am running Scanpy 1.8.1 and I can confirm that the indexing problem remains with Pandas 1.3.0, 1.3.2, and the latest 1.3.4, but resolves when downgrading to 1.2.5

1reaction
ivirshupcommented, Dec 14, 2021

My PR was merged, so this should be resolved with the next version of pandas.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Length of values (1) does not match length of index with sc.pp ...
I have checked that this issue has not already been reported. I have confirmed this bug exists on the latest version of scanpy....
Read more >
How to Fix: Length of values does not match length of index
This tutorial explains how to fix the following error in Python: valueerror: length of values does not match length of index.
Read more >
Length of values (1) does not match length of index (3) - Stack ...
You have the error because there is a single group. Example (using a function for clarity): def f(x): out = x['O'].isin(x['D']) ...
Read more >
ValueError: Length of values does not match length of index
Above code will raise the error Length of values does not match length of index because the DataFrame has four rows but the...
Read more >
Error while using sc.pp.calculate_qc_metrics - Help - Scanpy
The data I use is also your tutorial suggested. ... ValueError: Length of values (1) does not match length of index (2700).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found