STYLE: Use decorator syntax instead of legacy syntax for defining properties in Cython by jschendel · Pull Request #18602 · pandas-dev/pandas (original) (raw)

Yeah, now that you mention it, this does seem a bit strange, even the way it was originally written with the legacy syntax. I tried creating similar classes in plain Python and they all raised.

That aside, looking further into the code, it doesn't seem like value be a property? Or should at least have a setter? Maybe I'm missing something obvious (not super familiar with this part of the codebase or Cython in general), but it looks like there are places where value is being set, e.g.

obj = _TSObject()
if is_string_object(ts):
return convert_str_to_tsobject(ts, tz, unit, dayfirst, yearfirst)
if ts is None or ts is NaT:
obj.value = NPY_NAT

(and many other examples further below that)

Trying something similar on master raises, albeit in plain Python:

In [1]: from pandas._libs.tslibs.conversion import _TSObject

In [2]: obj = _TSObject()

In [3]: obj.value = 10

AttributeError: attribute 'value' of 'pandas._libs.tslibs.conversion._TSObject' objects is not writable

So I'm a little confused as to how this working in the snippet I posted from the codebase, but again, could just be my relative inexperience with Cython speaking.