BUG: Fix for DateOffset's reprs. (GH4638)
State: closed

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>
```


Labels:

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

@jreback Added some examples of before and after

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

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.

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.

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>>
```

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" notifications@github.com 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/pydata/pandas/pull/4868#issuecomment-24714237
> .

can you add some test for evaling the repr?

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

@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>
```

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

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

@jreback Should be good to merge.

Can you rebase this? Not mergeable right now.

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

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...

looks like there are merge conflicts fyi

@cpcloud @jtratner Issues should be resolved.

ping!

@cancan101 need to rebase 

Okay. Rebased

@cancan101 thanks!