Python Forum
Different results of code with local account and technical account
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Different results of code with local account and technical account
#1
Hi everyone,

I am running a forecasting code and am having a very weird issue.
My code is stored on a server and we have created a service account which takes the code and executes it.
This allows us to have the code launched automatically based on a scheduler.

My issue is now the following.
My code is failing when I am executing it using the service account and job scheduler.
I get an arithmetic overflow:
pyodbc.DataError: ('22003', '[22003] [Microsoft][ODBC SQL Server Driver][SQL Server]Arithmetic overflow error converting float to data type numeric. (8115) (SQLExecDirectW); [22003] [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated. (3621)')

Now this is normal given that apparently the number I am trying to upload is: 1.0753157419192108e+264

The thing is, if I take this exact code and run it but with my user account (throught the command terminal). I get no error message and this number:2.812633513

Does anyone know what could be the source of these two behaviors?
Again, the code is EXACTLY the same. I literally copy and pasted the same version of it.
I have no clue what is wrong :(

Would anyone be able to help?
Thanks!
Cheers
Reply
#2
This sounds like an MS SQL question, probably not a Python question.
Reply
#3
(Feb-28-2020, 12:42 AM)micseydel Wrote: This sounds like an MS SQL question, probably not a Python question.

Hi Micseydel
Thank you for your answer.
The SQL error seems to have pop up as a result of the issue when we try to upload our results into the database.

What I did is uncomment the part and re-ran the code.
I basically plotted the numbers that the algorithm spits out when ran using my normal account and using the technical account on our server.
I still get different numbers even though the code is the same...

Running it on my computer i get these numbers:
0
2019-02-01 2.818704599
2019-03-01 2.91823362
2019-04-01 3.04171862
2019-05-01 1.400378323

When i ran it using the job server and technical account:
2019-02-01 NaN
2019-03-01 NaN
2019-04-01 NaN
2019-05-01 NaN

Anyone knows what could be the issue?
Reply
#4
You really need to provide more details. If your question is about Python code, we need to see the code that causes the problem. (If that code more than about ten lines, I highly recommend you come up with example code which is minimized to reproduce your problem, hard-code as much as possible.) As for the most recent results you posted, I'm not especially familiar with MS SQL but you'll need to provide your queries if you want people to comment on the results.
Reply
#5
(Mar-02-2020, 07:03 PM)micseydel Wrote: You really need to provide more details. If your question is about Python code, we need to see the code that causes the problem. (If that code more than about ten lines, I highly recommend you come up with example code which is minimized to reproduce your problem, hard-code as much as possible.) As for the most recent results you posted, I'm not especially familiar with MS SQL but you'll need to provide your queries if you want people to comment on the results.

hi Micseydel,

here is the code:

from datetime import datetime, timedelta
import pandas as pd
import numpy as np
import ast
from warnings import catch_warnings
from warnings import filterwarnings
from statsmodels.tsa.holtwinters import ExponentialSmoothing
import time
import sqlite3
import pyodbc as msql
from dateutil.relativedelta import relativedelta

def lit_eval(strg):
    if type(strg) == str:
        return ast.literal_eval(strg)
    else:
        return strg

def pd_dict2list(row):
    return [value for key, value in row.items()][0:-1]

def frcst_cot(y, model, setup, fcst_hrz):
    result = None
    try:
        # never show warnings when grid searching, too noisy
        with catch_warnings():
            filterwarnings("ignore")

            t, d, s, p, b, r = setup
            # fit model
            model = ExponentialSmoothing(y, seasonal_periods=p, trend=t, seasonal=s, damped=d).fit(use_boxcox=b,
                                                                                                   remove_bias=r)
            yhat_v = model.predict(len(y) - fcst_hrz)
            yhat = model.forecast(fcst_hrz)
            result = pd.concat([yhat_v, yhat], axis=0)
    except:
        error = None
        result = None

    # if no forecasting was done applying generic model    
    if result is None:
        print('result is none, trying generic model...')
        try:
            # never show warnings when grid searching, too noisy
            with catch_warnings():
                filterwarnings("ignore")

                t, d, s, p, b, r = setup
                # fit model
                model = ExponentialSmoothing(y).fit()
                yhat_v = model.predict(len(y) - fcst_hrz)
                yhat = model.forecast(fcst_hrz)
                result = pd.concat([yhat_v, yhat], axis=0)
        except:
            error = None
            result = None

    # if results are still None using Naive model prediction 
    if result is None:
        print('result is still none, applying Naive model...')
        try:
            # never show warnings when grid searching, too noisy
            with catch_warnings():
                filterwarnings("ignore")

                forecst = y.copy()
                idx = pd.date_range(start=y.tail(1).index.min(), periods=fcst_hrz, freq='MS')
                forecst = forecst.reindex(idx, fill_value=0)
                forecst['Volume'] = y.tail(1).values[0][0]
                forecst = forecst.squeeze()
        except:
            error = None
    return result

# TODO: Add path to pickle file BEST_MODELS FILE
best_models = pd.read_pickle(r'C:\Users\XXX\Desktop\..\best_models.pkl')

starttime = time.time()

for itm in range(len(best_models)):
    row = best_models[itm:itm + 1]

    fcst_horizon = 12

    cols = (row.T != '(All)')
    cols.columns = ['chek']
    cols = cols[cols.chek == True].T

    needed_cols = list(set(cols.columns) - {'DATE', 'MODEL', 'SETUP', 'VERTEX'})

    qry_str = '\tand '.join([(c + ' == "' + row[c].values[0] + '" ') for c in needed_cols])

    # TODO: ADD PICKLE PATH COT_VERTEX
    CoT_vertex = pd.read_pickle(r'C:\Users\XXX\Desktop\..CoT_vertex.pkl')
    CoT_vertex = CoT_vertex.copy()

    CoT_vertex = CoT_vertex.pivot_table(index='Date', values=['Volume'], aggfunc=np.sum).reset_index()

    if CoT_vertex.Date.min() != CoT_vertex.Date.min():
        print('no COT data for:' + qry_str)
    else:
        if datetime.strptime(CoT_vertex.Date.max(), '%Y-%m-%d').date() >= (
                datetime.now().replace(day=1) + relativedelta(months=-2)).date():  # Added
            idx = pd.date_range(start=CoT_vertex.Date.min(), end=CoT_vertex.Date.max(), freq='MS')
            CoT_vertex.set_index('Date', inplace=True)
            CoT_vertex = CoT_vertex.reindex(idx, fill_value=0)
            CoT_vertex = CoT_vertex.squeeze()

            frcst = frcst_cot(CoT_vertex, row['MODEL'].values[0], row['SETUP'].values[0], fcst_horizon)

            print(frcst)

        else:
            print('Last COT older than 3m')
I tried to hardcode as much as I can but I am very new at Python so still struggling.
I am now looking to see how to send you the 2 pickle files so that you can run the code...
Reply
#6
(Mar-02-2020, 07:03 PM)micseydel Wrote: You really need to provide more details. If your question is about Python code, we need to see the code that causes the problem. (If that code more than about ten lines, I highly recommend you come up with example code which is minimized to reproduce your problem, hard-code as much as possible.) As for the most recent results you posted, I'm not especially familiar with MS SQL but you'll need to provide your queries if you want people to comment on the results.
Hi again,
Would you know how I can get to you the 2 pickle files? I don't see that I can attach files on the forum...
BEst
Reply
#7
Next post will be your fifth, so you will get the privilege to attach files

https://python-forum.io/misc.php?action=help&hid=31
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
(Mar-05-2020, 11:17 AM)buran Wrote: Next post will be your fifth, so you will get the privilege to attach files

https://python-forum.io/misc.php?action=help&hid=31
Omg yay :) Thanks!

(Mar-02-2020, 07:03 PM)micseydel Wrote: You really need to provide more details. If your question is about Python code, we need to see the code that causes the problem. (If that code more than about ten lines, I highly recommend you come up with example code which is minimized to reproduce your problem, hard-code as much as possible.) As for the most recent results you posted, I'm not especially familiar with MS SQL but you'll need to provide your queries if you want people to comment on the results.

Ok i don't see the attachment section.
But i have managed to put the 2 pickle files into a download link:
https://we.tl/t-Rr9O4XDs0N

Let me know if this is ok :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Modify an Energy Model to account for year dependent interest rate rather than only t giovanniandrean 0 425 Oct-10-2023, 07:00 AM
Last Post: giovanniandrean
  Code works but doesn't give the right results colin_dent 2 710 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Microsoft text phone verifying account cito 2 980 Jul-21-2022, 12:16 PM
Last Post: cito
  Output prints Account.id at the end? LastStopDEVS 5 2,762 Dec-19-2020, 05:59 AM
Last Post: buran
  Compiling Python 3.8.5 source code results in build error Deepan 0 2,178 Sep-14-2020, 04:11 AM
Last Post: Deepan
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,231 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,140 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  Error while Logging on to outlook email account using Python inside VDI Shilton 0 4,299 Sep-09-2018, 06:53 AM
Last Post: Shilton
  I need to MODIFY this to list all of the s3 buckets in my account , right now it will quantum_1 0 1,698 Jun-04-2018, 03:48 PM
Last Post: quantum_1
  financial technical indicators ian 2 3,149 Apr-23-2018, 12:25 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020