TabPy icon indicating copy to clipboard operation
TabPy copied to clipboard

Tableau Prep - Unwanted Date Change in Python script

Open tolivier-voo opened this issue 2 years ago • 4 comments

Environment information:

  • OS (TabPy Server): Windows 2016 on AWS EC2 Instance
  • Python version: 3.11.3
  • TabPy release: 2.9.0
  • OS (Tableau Prep): Windows 10 Entreprise

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

tolivier-voo avatar Dec 15 '23 09:12 tolivier-voo

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.

johng42 avatar Dec 15 '23 18:12 johng42

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)

tolivier-voo avatar Dec 21 '23 10:12 tolivier-voo

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...

johng42 avatar Dec 21 '23 16:12 johng42

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()
		})

tolivier-voo avatar Feb 22 '24 14:02 tolivier-voo