Skip to content

BUG: Fix for DateOffset's reprs. (GH4638) #4868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2013

Conversation

cancan101
Copy link
Contributor

closes #4638

Before:

In [22]: WeekOfMonth(weekday=1,week=2)
Out[22]: <1 WeekOfMonth: week=2, kwds={'week': 2, 'weekday': 1}, weekday=1>

In [32]: QuarterEnd()
Out[32]: <1 QuarterEnd: startingMonth=3, offset=<3 MonthEnds>>

In [40]: BQuarterBegin()
Out[40]: <1 BusinessQuarterBegin: startingMonth=3, offset=<3 BusinessMonthBegins>>

In [41]: BQuarterBegin(startingMonth=3)
Out[41]: <1 BusinessQuarterBegin: startingMonth=3, kwds={'startingMonth': 3}, offset=<3 BusinessMonthBegins>>

after:

In [2]: WeekOfMonth(weekday=1,week=2)
Out[2]: <1 WeekOfMonth: week=2, weekday=1>

In [3]: QuarterEnd()
Out[3]: <1 QuarterEnd: startingMonth=3>

In [4]: BQuarterBegin()
Out[4]: <1 BusinessQuarterBegin: startingMonth=3>

In [5]: BQuarterBegin(startingMonth=3)
Out[5]: <1 BusinessQuarterBegin: startingMonth=3>

@jreback
Copy link
Contributor

jreback commented Sep 18, 2013

can you show some examples of the before and after? (in the top of this PR)

@cancan101
Copy link
Contributor Author

@jreback Added some examples of before and after

@jtratner
Copy link
Contributor

Would it be easy to make eval(repr(offset)) work? It looks like it would be simple to do. Makes life easier/cleaner.

@cancan101
Copy link
Contributor Author

I suppose this could be done by:

  1. Dropping the < and > that wrap the repr
  2. Inserting a * between the leading n value and the class name
  3. Using the class name rather than an alternative representation (for example see BQuarterBegin and BusinessQuarterBegin)
  4. Expanding kwds
  5. Parenthesis inside rather than : after class name

Item 3 is the most complicated in the list.

@jtratner
Copy link
Contributor

Okay, sounds like it's not simple. What you have is fine, though I don't
understand why there's a number before the class name.

@cancan101
Copy link
Contributor Author

That is the n value:

In [8]: 2 * QuarterEnd(startingMonth=3)
Out[8]: <2 QuarterEnds: startingMonth=3, kwds={'startingMonth': 3}, offset=<3 MonthEnds>>

In [9]: QuarterEnd(n=2,startingMonth=3)
Out[9]: <2 QuarterEnds: startingMonth=3, kwds={'startingMonth': 3}, offset=<3 MonthEnds>>

@cancan101
Copy link
Contributor Author

Even if I don't make the repr work with eval, There might be some tweak
that will make the repr more understandable.

I am thinking of not printing n if it's 1, and inserting the times operator
otherwise.

Thoughts?
On Sep 18, 2013 10:57 PM, "Jeff Tratner" [email protected] wrote:

Okay, sounds like it's not simple. What you have is fine, though I don't
understand why there's a number before the class name.


Reply to this email directly or view it on GitHubhttps://github.com//pull/4868#issuecomment-24714237
.

@jreback
Copy link
Contributor

jreback commented Sep 19, 2013

can you add some test for evaling the repr?

@jtratner
Copy link
Contributor

Honestly, if it's understandable to you and @jreback, it's probably fine.
Not necessarily worth the time to make it more complicated.

@cancan101
Copy link
Contributor Author

@jreback I am not planning on having the eval work on the repr. That would require making a decent number of changes.

I am just suggesting cleaning up the format a bit.

For example, the new after:

In [2]: WeekOfMonth(weekday=1,week=2)
Out[2]: <WeekOfMonth: week=2, weekday=1>

In [3]: QuarterEnd()
Out[3]: <QuarterEnd: startingMonth=3>

In [4]: BQuarterBegin()
Out[4]: <BusinessQuarterBegin: startingMonth=3>

In [5]: BQuarterBegin(startingMonth=3)
Out[5]: <BusinessQuarterBegin: startingMonth=3>

In [6]: WeekOfMonth(n=2, weekday=1,week=2)
Out[6]: <2 * WeekOfMonth: week=2, weekday=1>

@jreback
Copy link
Contributor

jreback commented Sep 19, 2013

ok...this looks fine...pls rebase and squash

@cancan101
Copy link
Contributor Author

@jreback I still have to make the final change to formatting n. I will commit/squash/rebase then.

@cancan101
Copy link
Contributor Author

@jreback Should be good to merge.

@@ -741,7 +757,6 @@ def __init__(self, n=1, **kwds):
self.n = n
self.startingMonth = kwds.get('startingMonth', 3)

self.offset = BMonthEnd(3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what replaced this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line did nothing. self.offset is never read

@jtratner
Copy link
Contributor

Can you rebase this? Not mergeable right now.

@cancan101
Copy link
Contributor Author

Is there an easy way to tell in Github that I need to do a rebase?

@jtratner
Copy link
Contributor

Not really - committers can see it. You can tell in git...just try to either (1) rebase on top of master or (2) merge with master.

In general, it's helpful if you just periodically rebase and push (since it keeps the history nicer). If there are no merge conflicts, you don't have to do anything. If there are merge conflicts, we'd be asking you to rebase anyways, so you'll have to deal with them eventually regardless...

@cpcloud
Copy link
Member

cpcloud commented Sep 24, 2013

looks like there are merge conflicts fyi

@cancan101
Copy link
Contributor Author

@cpcloud @jtratner Issues should be resolved.

@cancan101
Copy link
Contributor Author

ping!

@jtratner
Copy link
Contributor

@cancan101 need to rebase

@cancan101
Copy link
Contributor Author

Okay. Rebased

@@ -247,7 +259,7 @@ def __init__(self, n=1, **kwds):
def rule_code(self):
return 'B'

def __repr__(self):
def __repr__(self): #TODO: Figure out if this should be merged into DateOffset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this actually still a TODO?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cancan101 all I mean is that presumably you'd be making this decision now - right? Otherwise I'll merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I have to take a look to figure out why some/all of the repr code was duplicated here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw what looked like code duplication but did not have the time to look into it.

jtratner added a commit that referenced this pull request Sep 27, 2013
BUG: Fix for DateOffset's reprs. (GH4638)
@jtratner jtratner merged commit ed030e9 into pandas-dev:master Sep 27, 2013
@jtratner
Copy link
Contributor

@cancan101 thanks!

@cancan101 cancan101 deleted the offset_repr branch October 20, 2013 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPR: kwds in DateOffset
4 participants