question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DISC: Period.__le__

See original GitHub issue

There are a bunch of issues outstanding that relate to Period ops and comparison. AFAICT making a decision about the comparison issue will snowball into resolving (some of) the ops issues.

#5202 ENH: Period ops NaT & timedelta ops #10798 Date / Datetime in Period Index #6779 Adding Period and Offset not implemented #13077 ENH/API: Decide what to return Period - Period subtraction #17112 MultiIndex - Comparison with Mixed Frequencies (and other FUBAR)

Right now two Period objects are comparable iff they equal freq attributes. AFAICT this is to avoid guessing in cases where the “correct” answer is ambiguous. But there are some other cases with an obviously correct answer. Namely, if the per1.end_time < per2.start_time, then it should be the case that per1 < per2 unambiguously. This intuition also extends to datetime and Timestamp objects that do not lie between per.start_time and per.end_time.

For cases with overlap there are a couple of reasonable approaches. My preferred approach is lexicographic: first compare per1.start_time with per2.start_time. If they are equal, then compare the end_times. Then we treat datetime and Timestamp objects as analogous to zero-duration periods.

Thoughts?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Sep 27, 2017

yeah in an ideal work we would actually use an Interval to back a Period. Yes we should clarify the semantics here.

1reaction
shoyercommented, Sep 27, 2017

Another point of reference is Interval, which uses lexicographic ordering on (start, stop, closed): https://github.com/pandas-dev/pandas/blob/d3be81ad595c5338781bed9963c729a9702e6611/pandas/_libs/interval.pyx#L91-L94

So if we care about ordering periods with different frequencies, this would be a reasonable choice. On the other hand, if we don’t have use cases for this, from a usability perspective it is probably better to stick with refusing to order potentially overlapping periods.

Then we treat datetime and Timestamp objects as analogous to zero-duration periods.

So period < timestamp would effectively compare period.start_time < timestamp? I suppose we could argue that this is consistent, but here I really don’t think it’s a good idea. It’s better to force users to be explicit about what they want rather than allow them to make mistaken assumptions (period.end_time < timestamp is at least as plausible).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Menstrual Disc: What to Know Before You Try
A menstrual disc is an insertable alternative period product that's supposed to provide 12 hours of protection, let you have mess-free sex on...
Read more >
Flex® | Period products, reimagined
THE ECO FRIENDLY. PLANT+ DISC. Cool fact: Flex Plant+ Disc is made with 40% plant-based polymers that capture CO2 from the atmosphere during...
Read more >
How to Use a Menstrual Disc: Expectations vs. Reality
Both a menstrual cup and a disc collect menstrual blood inside your body and are a great sustainable alternative to tampons and pads....
Read more >
Ziggy Cup ™ 2 - Reusable Menstrual Disc
Ziggy 2 is redesigned menstrual disc that truly offers you infinite possibilities. It can be worn during sex while offering you the best...
Read more >
Hello Disc Features | Accessible Menstrual Disc Design #shorts
How does the Hello Disc work and why is it different than other ... Pre-order today from www. period.shop with expected shipping in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found