-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Describe the bug There is a type inconsistency between the def_geo1 function signature and its internal validation function check_on_geo1.
While def_geo1 is defined to accept numpy.ndarray for several parameters (such as sens_dir, sens_lines, bg_nodes, etc.), the validation logic inside check_on_geo1 treats these inputs as Pandas DataFrames. This results in an AttributeError (e.g., 'numpy.ndarray' object has no attribute 'values') when providing data directly as arrays, as suggested by the function's type hints.
To Reproduce Steps to reproduce the behavior:
Create a Python script and import pyoma2.
Define the geometry variables directly in the script using numpy arrays (do not load them from an Excel file).
Call def_geo1 using these variables.
Run the script on Windows 10 with pyoma2 v1.2.1.
Python
import numpy as np
import pandas as pd
from pyoma2.functions import Gen_Func
Example of manual definition that triggers the error
sens_names = ['S1', 'S2']
sens_coord = pd.DataFrame([[0, 0, 0], [1, 1, 1]], columns=['x', 'y', 'z'])
Defined as ndarray as per type hint
sens_dir = np.array([[1, 0, 0], [0, 1, 0]])
This call will fail during internal validation
geo = Gen_Func.def_geo1(
sens_names=sens_names,
sens_coord=sens_coord,
sens_dir=sens_dir
)
Expected behavior The function should support numpy.ndarray inputs as specified in the type hints. The validation logic should check the type of the input before accessing attributes like .values or .empty, or internally convert arrays to DataFrames.
Desktop:
pyoma2 version: 1.2.1
OS: Windows 10
Additional context or possible solutions The error occurs because check_on_geo1 attempts to use Pandas-specific methods on NumPy arrays.
Example 1: Accessing .values on an array
Python
check_on_geo1 logic:
if (file_dict["sensors coordinates"].values.shape
!= file_dict["sensors directions"].values.shape):
# Fails if "sensors directions" is already an ndarray
Example 2: Using .empty on an array
Python
check_on_geo1 logic:
if (file_dict.get("BG nodes") is not None
and not file_dict["BG nodes"].empty # Fails if BG nodes is ndarray
and file_dict["BG nodes"].values.shape[1] != 3):
...
Proposed solution: Standardize the input within def_geo1 before calling check_on_geo1, or update check_on_geo1 to handle both pd.DataFrame and np.ndarray gracefully.