We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

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
20 - Arcturus

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
15 - Aurora
15 - Aurora

@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

 

All the best,
BS

LinkedIN

Bulien
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
15 - Aurora
15 - Aurora

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. 

 

All the best,
BS

LinkedIN

Bulien
BS_THE_ANALYST
15 - Aurora
15 - Aurora

@ngrahl you can supply a dataframe aswell:

BS_THE_ANALYST_0-1687374174341.png


This seems like it should sort your issue.

 

All the best,
BS

LinkedIN

Bulien
ngrahl
5 - Atom

Dan,

 

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

Labels
Top Solution Authors