tableau / TabPy

Execute Python code on the fly and display results in Tableau visualizations:
https://tableau.github.io/TabPy/
MIT License
1.55k stars 592 forks source link

Tableau Prep - Unwanted Date Change in Python script #627

Open tolivier-voo opened 9 months ago

tolivier-voo commented 9 months ago

Environment information:

Describe the issue With a very simple python script (And more complicated too), a date sent to TabPy with no modification in the script, comes back one day earlier...

This issue doesn't appear in all environments, I guess it's maybe an issue with timezone conversion, and substract some hours on date field too

To Reproduce There is a packaged flow on this page : https://community.tableau.com/s/question/0D58b00009weKJvCAM/issue-with-dates-being-shifted-1-day-earlier-in-tableau-prep

Expected behavior The date must stay the same

Screenshots Case 1 : original_data_2 output_data_2 Case 2: original_data_1 output_data_1

Additional context https://community.tableau.com/s/question/0D58b00009weKJvCAM/issue-with-dates-being-shifted-1-day-earlier-in-tableau-prep

johng42 commented 9 months ago

I'll start with the obvious question - what time zone is set on each machine?

I suspect this line in ...\TabPy-master\TabPy-master\tabpy\tabpy_tools\rest_client.py (line 9)

    return datetime.utcfromtimestamp(value)

In this case, the value of the date is changed to UTC and that may not be the same as the expected time zone. That might throw off the value by enough to make this date appear as the wrong day.

    return datetime.fromtimestamp(value)

might work. I don't any way to test that but it could be worth a shot to see if that would fix, or at least change, the behavior.

tolivier-voo commented 9 months ago

Thanks for your answer,

How can I try that (To recompile and modify this file on an pip tapby installation)

The 2 computers (Server and Local) are on the same Timezone (Brussels Time)

johng42 commented 9 months ago

I think you could simply find and modify the rest_client.py file on the server. When I last worked on tabpy, we didn't compile the python code so that should be enough. Restarting the server after the modification may also be needed.

That will at least identify if this line might need to be updated. There is more testing that will need to be done before accepting this change. For example, this particular line appears to be a fallback case so the root cause to avoid the fallback might suggest a better fix elsewhere...

tolivier-voo commented 7 months ago

Hello,

Sorry for the late reply, busy time,

I've tried this change bu this issue is still occuring. image image

Test Script Content :

import pandas as pd

def main_function(input_df):
    return input_df

def get_output_schema():
    return pd.DataFrame({
        'ID': prep_string(),
        'Name': prep_string(),
        'Date': prep_date()
        })