AttributeError in pandas when run from terminal but not PyCharm

Viewed 30

I have a code that runs everyday and processes data from electrochemical processes. This code originally worked fine and ran smoothly. I updated it to add a new ID column to the DataFrame. Everything worked fine on my computer in PyCharm and from the terminal. It worked on my colleague's computer in Spyder with Anaconda. When I put it on our computer that holds all our automation scripts, I get the error,

  File "C:\automation_tools\magnesium-calculator\mg_algorithm.py", line 95, in get_slope
    a = df.loc[df["CalType"] == "A", sensor].to_numpy(dtype=np.double)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py", line 3081, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'to_numpy'

This goes back to my function,

def get_slope(df, cons, sensor):
(
...
) = unpack_cons(cons)

    a = df.loc[df["CalType"] == "A", sensor].to_numpy(dtype=np.double)
    b_bef_a = get_bef_val(df, sensor, "B", "A").to_numpy(dtype=np.double)

    slope = (a - b_bef_a) / np.log10(bag_a / bag_b)

    s = pd.DataFrame(slope, index=df.loc[df["CalType"] == "A", sensor].index)

    return s

I do not know why this error is arising. I am confused because it even works in PyCharm on the computer whose terminal produces this error. They use the same venv with python 3.9.6. I have double checked all versions and they are the same.

    Package         Version
--------------- -------
et-xmlfile      1.1.0
numpy           1.21.3
openpyxl        3.0.9
pandas          1.3.4
pip             21.1.2
python-dateutil 2.8.2
pytz            2021.3
setuptools      57.0.0
six             1.16.0
wheel           0.36.2

Is there anything I could be missing here?

Edit: I did activate the venv when I ran it from the terminal in every case. It worked with the original script I wrote and now, with the same venv, it raises an error.

0 Answers
Related