python pandas to_datetime, getting segmentation fault

Viewed 110

I have some code to adjust some dates. When I use datetime objects, it all works fine, whether I adjust them using python.datetime as a method (dfix) or as a function (dfix2). But if I use objects created by pandas.to_datetime (which I thought were supposed to be compatible), python.datetime works fine as a method (pfix) but can cause a segmentation fault when used as a function (pfix2). Code and output below:

import datetime

import pandas

d = datetime.datetime(1970, 1, 1, 12, 0, 0)
dfix = d.replace(year=2001)
dfix2 = datetime.datetime.replace(d, year=2001)

p = pandas.to_datetime("1970-01-01T12:00:00")
pfix = p.replace(year=2001)
pfix2 = datetime.datetime.replace(p, year=2001)

match = dfix == dfix2
print("dfix == dfix2 = %s" % match)

match = dfix == pfix
print("dfix == pfix = %s" % match)

match = dfix2 == pfix
print("dfix2 == pfix = %s" % match)

match = pfix == pfix2
print("pfix == pfix2 = %s" % match)

# either of these lines causes a segmentation fault, on Mac OS 12.0,
# Python 3.8.10 (default, May 19 2021, 11:01:55) 
# [Clang 10.0.0 ] :: Anaconda, Inc. on darwin
# pandas version 1.1.3

match = dfix == pfix2
match = dfix2 == pfix2

output:

dfix == dfix2 = True
dfix == pfix = True
dfix2 == pfix = True
pfix == pfix2 = False
Segmentation fault: 11

Now I can work around this by using datetime.replace as a method, but I am wondering: have I stumbled on a pandas bug? Or is there a good reason for this happening? (Or is it specific to my setup: can anyone reproduce this?)

0 Answers
Related