2

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.

  • You have to activate the venv. – bad_coder Oct 21 '21 at 15:26
  • @bad_coder the venv was activated for all scenarios – Lance Harms Oct 21 '21 at 15:51
  • There aren't many [occurrences of this error](https://stackoverflow.com/search?q=%22+%27DataFrame%27+object+has+no+attribute+%27to_numpy%27%22). From your description I'd say this is not reproducible. We have no way of verifying what the differences between those systems are. If it works from the terminal emulator inside the IDE there's no obvious reason why it shouldn't work on the same terminal outside the IDE. I'd recommend clearing environment variables and creating a clean venv from scratch. – bad_coder Oct 21 '21 at 16:18
  • I forgot to clarify, it doesn't work from the terminal emulator in the IDE either. It runs when I click run 'main' with the same venv. I cleared environmental variables and created a new venv and the same issue occurs everytime. – Lance Harms Oct 21 '21 at 17:33
  • Then your latest comment just contradicted the description given in the question. – bad_coder Oct 21 '21 at 19:18
  • In PyCharm, there is a terminal emulator that allows for command line coding. There is also the run button in the script editor area. The run button executes the code without issues but if I run it from the terminal emulator then this error is raised, just like if I ran from the actual terminal. This only happens on this one specific computer. They are both using the same venv as the interpreter. This error did not occur until I updated the main code. But this function was not touched and the input to this function has not changed. – Lance Harms Oct 21 '21 at 20:29

0 Answers0