Search code examples
pythonpandaspickle

Any difference between using .pickle/pkl file extension vs no extension when working with pickle files with pandas?


I have noticed that all three of these seem to produce the same result (df is a pandas dataframe):

df.to_pickle('df')
df.to_pickle('df.pkl')
df.to_pickle('df.pickle')

I read here that there is no difference between .pkl and .pickle but how about using no extension at all like the first one above? Acceptable?


Solution

  • No, there is no difference programmatically. The encoding of the file contents will be the same.

    That said, there is a huge difference when people come to decode the file to try and get something useful back out of it. If you send me a file with no extension then I have absolutely no starting point to guess on how to decode it into something meaningful.

    Now, the final thing to say here is that distributing pickle files and having a client read them is a real security threat. One could argue that pickle files would never be distributed, and only used internally in a program itself; in which case, just do yourself and your developers a favour and pick either .pkl or .pickle