[Python-ideas] bool(datetime.time(0, 0)) vs missing data

Jim Jewett jimjjewett at gmail.com
Wed May 9 18:38:19 CEST 2012


On Wed, May 9, 2012 at 2:07 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Tue, 8 May 2012 20:53:58 -0400
> Jim Jewett <jimjjewett at gmail.com> wrote:
>> On Mon, May 7, 2012 at 12:06 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:

>> > ... Does midnight warrant any special ...

>> Why do you think that 0 represents midnight?   *Because* it is zero,
>> it will often be used as a default for missing data.

> Well, if you've decided upfront that midnight "is zero", then you may
> argue it's special. But as others have shown, there's nothing obvious
> about midnight being "zero", especially with timezones factored in.
> For example, there are no binary operators where midnight is a "zero"
> i.e. a neutral element.

The cyclic groups Z/n have a zero element, so *something* has to be
effectively zero; start of day is as reasonable as anything else.  Or
are you just saying that there aren't *any* meaningful binary
operators on hour-of-the-day, beyond __eq__ and __ne__?

Practicality Beats Purity suggests that at least comparisons should
work consistently, so that time-of-day can be consistently ordered,
and that requires a least element.  (You could make it noon, or  mean
sunrise, or actual sundown at a certain monument, but you do need
one.)

> Besides, we have a special value called None exactly for the purpose of
> representing missing data.

Not really at the moment, since datetime.time doesn't accept it as an
argument, and itself uses 0 for missing data.  That could *probably*
be fixed in an upwards compatible way, but you would still have to
special case how missing-data times should compare to current class
instances.

    # Should they ever be equal?
    # If not, mixing types is a problem.
    time(hour, min, sec, microsecond)  ==
    Time(hour, min, sec, microsecond)  ?

    # Should microseconds be required?
    # If not, mixing types is a problem.
    time(hour, min, sec, microsecond=0)  ==
    Time(hour, min, sec, microsecond=None)  ?

    # Should even hours be required?
    # If so, how much precision is logically required?
    time(hour=0, min=0, sec=0, microsecond=0)  ==
    Time(hour=None, min=None, sec=None, microsecond=None)  ?

    # datetime.time already skips the date.
    # Can hours be skipped too, to indicate "every hour on the hour"?
    Time(hour=None, min=0, sec=0, microsecond=0)  ?

    # Should missing data never match, match 0, or match anything (the
"on the hour" case)
    time(hour=7, min=15, sec=0, microsecond=0)  ==
    Time(hour=None, min=15, sec=0, microsecond=0)  ?

-jJ



More information about the Python-ideas mailing list