Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tableau Prep - Unwanted Date Change in Python script #627

Open
tolivier-voo opened this issue Dec 15, 2023 · 4 comments
Open

Tableau Prep - Unwanted Date Change in Python script #627

tolivier-voo opened this issue Dec 15, 2023 · 4 comments
Labels

Comments

@tolivier-voo
Copy link

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

@johng42
Copy link
Contributor

johng42 commented Dec 15, 2023

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
Copy link
Author

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
Copy link
Contributor

johng42 commented Dec 21, 2023

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
Copy link
Author

tolivier-voo commented Feb 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants