Hi everyone,

I’m encountering an error during model fitting in my TVP-PVAR model using PyMC v5. The error message is:

Unsupported dtype for TensorType: object

I’ve tried several things to troubleshoot, but I’m still stuck. Here’s some background:

- I have a custom class
`TVPPVARFitter`

that handles data loading, imputation, and model fitting. - I’ve tried various imputation methods (
`kalman`

,`iterative`

,`knn`

) to address missing values, but the error persists. - I’ve explicitly cast data to
`float32`

before feeding it to the model (in the`fit_tvp_pvar`

method). - I’ve verified that all variables in the data used for fitting are indeed of type
`float32`

(shown in the data loading section).

**Code Snippets:**

**Data Loading (relevant part):**

```
# Import libraries
import pandas as pd
import numpy as np
import pymc as pm # PyMC 5.15.1
import arviz as az
# Load data from CSV file
df = pd.read_csv('data.csv')
# Filter data to include only records from 1990 onwards
df = df[df['year'] >= 1990]
# Create vars_to_float list with only numerical columns
vars_to_float = [col for col in df.columns if df[col].dtype in ['float64', 'int64']]
# Filter vars_of_interest to include only those in vars_to_float
vars_to_float = list(set(vars_to_float) & set(vars_of_interest))
# Ensure all variables in vars_to_float are treated as float32
df[vars_to_float] = df[vars_to_float].astype('float32')
# Print data types to verify they are float32
print(df[vars_to_float].dtypes) # This should show all data types as 'float32'
df_float = df[vars_to_float].copy()
model = TVPPVARFitter(df_float, vars_to_float, p=1) # Assuming p=1 for lag order
```

`fit_tvp_pvar`

method (relevant part):

```
def fit_tvp_pvar(self, num_iterations=10000, burn=5000, tune=5000, cores=1, delay=1):
# ... (other parts of the method)
# Imputation logic
from sklearn.experimental import enable_iterative_imputer # Import for iterative imputer
from sklearn.impute import IterativeImputer, KNNImputer # Imports for imputation methods
imputation_methods = ['kalman', 'iterative', 'knn']
imputed = False
for method in imputation_methods:
# ... (imputation steps using the chosen method)
if not np.any(np.isnan(data)) and not np.any(np.isinf(data)):
imputed = True
self.n_vars = data.shape[1]
break
# Convert to float32 again (for safety)
data = np.array(data, dtype=np.float32)
# ... (rest of the model fitting logic)
# Import PyMC and ArviZ
import pymc as pm # PyMC 5 for model definition
import arviz as az # ArviZ for diagnostics and visualization
# ... (model definition and MCMC sampling using PyMC and ArviZ)
```

**Questions:**

- Has anyone encountered a similar “object” type error with PyMC?
- Are there any additional debugging strategies I can use to pinpoint the source of these non-numeric values (besides checking data types)?
- Could there be other reasons for this error besides missing values?

4 Could anyone help on how to modify the code?

I have not used pytensor. I suspect it was unnecessary. Pymc v 5 handles tensors internally.

**Additional Information:**

- PyMC version: 5.15.1
- Libraries used: numpy, pandas, sklearn, pymc, arviz, matplotlib, pykalman

**Note:** I haven’t included the entire `fit_tvp_pvar`

method or data pre-processing steps (like filtering by year) for brevity. However, the provided snippets highlight the key areas related to data loading, imputation, and type casting.

pytensor

Thank you wholehardly in advance for any help you can provide

Best regards

Dimitri