python-holidays icon indicating copy to clipboard operation
python-holidays copied to clipboard

Can't pickle the result of `country_holidays`

Open Mr-Geekman opened this issue 1 year ago • 4 comments

Currently, on Linux it isn't possible to pickle the result of calling country_holidays.

Code to reproduce:

import pickle
import holidays


def main():
    jp_holidays = holidays.country_holidays("JP")
    result = pickle.dumps(jp_holidays)


if __name__ == "__main__":
    main()

The error: _pickle.PicklingError: Can't pickle <function func at 0x7f9098a8dd30>: attribute lookup func on __main__ failed.

It fails not on all countries. For example, it works for US and UK.

The error starts from version 0.22 (on 0.22 it is slightly different).

The problem can be fixed by using dill, but may be it is possible to adjust the code to work with native pickle.

Mr-Geekman avatar May 25 '23 11:05 Mr-Geekman

Thanks for reporting this. I guess i18n related code might be the culprit. I suggest using the workaround you found until the issue is fixed.

Sorry for the inconvenience.

arkid15r avatar May 31 '23 01:05 arkid15r

@Mr-Geekman On current beta 0.26 that code produce no error, so I would advise you to wait for next release and check with it. The release is planned for early June.

KJhellico avatar May 31 '23 10:05 KJhellico

@Mr-Geekman On current beta 0.26 that code produce no error, so I would advise you to wait for next release and check with it. The release is planned for early June.

Hmmm, can't confirm that after a brief look...

arkid15r avatar May 31 '23 23:05 arkid15r

Yes, it seems pickle can't process holidays with language other than default. :-(

KJhellico avatar Jun 01 '23 13:06 KJhellico