Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Python Developer Alteryx.write converts a datetime field to date field

ngrahl
5 - Atom

When using the Alteryx.write() function, I am having a problem with it converting a datetime field to date only.

ngrahl_0-1687359039006.png

 

7 REPLIES 7
geraldo
13 - Pulsar

@ngrahl 

 


It was not clear your problem with the python tool.
By the print everything is correct

apathetichell
18 - Pollux

I'd recommend writing it as a string and converting it in-workflow. I have not seen this specific issue but I've done that with other datatypes (fixed decimal with greater than 6 digits)... Some of this truncation can occur when you are converting from Python to C at the C function level (at least that is my hypothesis...)

BS_THE_ANALYST
14 - Magnetar

@ngrahl based off this little simulation, all is working fine:

BS_THE_ANALYST_0-1687369713569.png



I'm thinking that when you did the reset_index(), you forgot to put inplace=True as an argument ..:

BS_THE_ANALYST_1-1687369848729.png


Difficult to tell as you've cut your code off in the screenshot.


I've attached the demo workflow. Compare & Contrast to figure it out. Definitely check your reset_index step is saying inplace=True

 

danilang
19 - Altair
19 - Altair

Hi @ngrahl 

 

It looks the error can occur if the first record in your input has 00:00:00.  

danilang_0-1687370264831.png

but outputs correctly otherwise, which explains @BS_THE_ANALYST's result

danilang_1-1687370346932.png

This post goes more in depth and includes a nice hack to explicitly set the the data types to fix the issue.

 

Dan  

 

BS_THE_ANALYST
14 - Magnetar

I had a dig into the issue & I think I've solved it in a simple way. Have a test @danilang :

BS_THE_ANALYST_0-1687372084167.png

Essentially this forces the metadata when writing out with the metadata inside the Python tool. 

 

BS_THE_ANALYST
14 - Magnetar

@ngrahl you can supply a dataframe aswell:

BS_THE_ANALYST_0-1687374174341.png


This seems like it should sort your issue.

 

ngrahl
5 - Atom

Dan,

 

Thank you for the embedded link.  I incorporated the additional Python code, and the problem is solved.

Labels