Data class constructor does not save the procnames value

Open Beginner friendly
#96 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start in pyspi/data.py at Data.init and the procnames() property referenced by the issue. Run the provided reproduction to confirm the supplied names are ignored; done means Data.procnames and the Calculator table use the requested process names.

Written by the indexing model from the issue text.

Description

When calling the Data constructor Data.__init__, the constructor accepts procnames as a value, which it then validates:
https://github.com/DynamicsAndNeuralSystems/pyspi/blob/46ccfd522488ea518011c162f1e550ba4a1a013c/pyspi/data.py#L82-L83
but it never save the value, which it then attempts to read in the procnames() function:
https://github.com/DynamicsAndNeuralSystems/pyspi/blob/46ccfd522488ea518011c162f1e550ba4a1a013c/pyspi/data.py#L100-L106
Since self._procnames is never set procnames will always return the generated names.

The issue can be seen when running the following code(Generated by Claude Opus 5):

import inspect
import platform
import sys
from importlib.metadata import PackageNotFoundError, version

import numpy as np
from pyspi.calculator import Calculator
from pyspi.data import Data


def pkg_version(name: str) -> str:
    try:
        return version(name)
    except PackageNotFoundError:
        return "not installed"


print("--- environment")
print(f"python : {sys.version.split()[0]} ({platform.platform()})")
for pkg in ("pyspi", "numpy", "pandas"):
    print(f"{pkg:<7}: {pkg_version(pkg)}")
print(f"Data signature: {inspect.signature(Data)}")

# 3 processes x 100 observations, rows are processes (dim_order="ps")
X = np.random.default_rng(0).normal(size=(3, 100))
names = ["wrist", "thumb", "index"]

print("\n--- 1. Data object")
data = Data(data=X, dim_order="ps", procnames=names)
print(f"expected procnames: {names}")
print(f"actual procnames  : {list(data.procnames)}")
data_ok = list(data.procnames) == names

print("\n--- 2. Calculator table")
calc = Calculator(dataset=data, subset="fabfour")
calc.compute()
spis = list(dict.fromkeys(calc.table.columns.get_level_values(0)))
spi = "cov_EmpiricalCovariance" if "cov_EmpiricalCovariance" in spis else spis[0]
print(f"calc.table[{spi!r}]:")
print(calc.table[spi])
table_ok = list(calc.table.index) == names

print("\n--- result")
print(f"Data.procnames uses given names : {data_ok}")
print(f"Calculator.table uses given names: {table_ok}")
if data_ok and table_ok:
    print("Not reproduced: procnames were applied.")
    sys.exit(0)
print("Reproduced: procnames passed to Data are not applied.")
sys.exit(1)

It produces the following output:

--- environment
python : 3.12.10 (Windows-11-10.0.26100-SP0)
pyspi  : 2.0.1
numpy  : 1.26.4
pandas : 2.3.3
Data signature: (data=None, dim_order='ps', detrend=False, normalise=True, name=None, procnames=None, n_processes=None, n_observations=None)

--- 1. Data object
[1/2] Skipping detrending of time series in the dataset...
[2/2] Normalising (z-scoring) each time series in the dataset...

expected procnames: ['wrist', 'thumb', 'index']
actual procnames  : ['proc-0', 'proc-1', 'proc-2']

--- 2. Calculator table
calc.table['cov_EmpiricalCovariance']:
process    proc-0    proc-1    proc-2
proc-0        NaN  0.054899 -0.013441
proc-1   0.054899       NaN  0.030280
proc-2  -0.013441  0.030280       NaN

--- result
Data.procnames uses given names : False
Calculator.table uses given names: False
Reproduced: procnames passed to Data are not applied.

Dominant language
Python
Stars
256
Forks
34
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DynamicsAndNeuralSystems/pyspi

All issues in DynamicsAndNeuralSystems/pyspi

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.