2

Haven't found any way to mutate an existing pandas.Timestamp myself, but also have not found any documentation explicitly stating it to be immutable.

Anyone knows the answer or has a way to find out?

Mark Horvath
  • 1,136
  • 1
  • 9
  • 24
  • 1
    Related answer: [pd.Timestamp versus np.datetime64: are they interchangeable for selected uses?](https://stackoverflow.com/a/49758140/9209546) – jpp May 04 '18 at 12:50

1 Answers1

2

After looking to the source code, I found out the inherit from datetime.datetime which is immutable.

# in pandas/_lib/tslibs/timestamp.pyx
cdef class _Timestamp(datetime):
# ...
class Timestamp(_Timestamp): # This is the class that is exported

If you look inside the python implementation of datetime you see that it is supposed to be immutable (via onway properties):

# Read-only field accessors
@property
def year(self):
    """year (1-9999)"""
    return self._year

@property
def month(self):
    """month (1-12)"""
    return self._month

@property
def day(self):
    """day (1-31)"""
    return self._day

@property
def hour(self):
    """hour (0-23)"""
    return self._hour

@property
def minute(self):
    """minute (0-59)"""
    return self._minute

@property
def second(self):
    """second (0-59)"""
    return self._second

@property
def microsecond(self):
    """microsecond (0-999999)"""
    return self._microsecond
MegaIng
  • 7,361
  • 1
  • 22
  • 35