Skip to content
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

ENH: adding __str__ and __repr__ methods to classes #114

Merged
merged 4 commits into from
Jan 30, 2015
Merged

ENH: adding __str__ and __repr__ methods to classes #114

merged 4 commits into from
Jan 30, 2015

Conversation

sglyon
Copy link
Member

@sglyon sglyon commented Jan 29, 2015

This is not quite finished.

I am just opening this pull request so I can keep track of notes I collect as I go.

I will leave a comment saying it is ready to go at the appropriate time.

@sglyon
Copy link
Member Author

sglyon commented Jan 29, 2015

Comments so far:

  • I don't have a great __str__ method for ARMA. Any suggestions are welcome
  • I am still struggling with how to represent attributes of the class that are functions. I would really like the __repr__ methods to return a copy/pasteable string that would re-create the object, but I don't know if this is possible. I tried using inspect.getsource, but that didn't work so well because it just returns the entire contents of each line containing the definition. For example, when I asked for the contents of ConsumerProblem.du it gave me this whole line, which also contains the definition of ConsumerProblem.u. I could manually parse it, but that seems like more work than we should be doing for this convenience feature and very fragile.

@sglyon sglyon mentioned this pull request Jan 29, 2015
14 tasks
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.85%) to 92.37% when pulling 505033f on repr into 26bc87e on master.

@sglyon
Copy link
Member Author

sglyon commented Jan 29, 2015

More comments:

  • Because their arguments are mostly arrays, the idea of having __repr__ return a string that can recreate the object is not feasible for the Kalman, LAE, LQ, LSS, RBLQ, and ECDF. I have just implemented somewhat meaningful __str__ methods and am having __repr__ just call __str__ for now.

@sglyon
Copy link
Member Author

sglyon commented Jan 29, 2015

@oyamad

The DiGraph class was contributed by you (thanks!) and I have I implemented very basic versions of these methods, feel free to change them if you think a different message would be better

@sglyon
Copy link
Member Author

sglyon commented Jan 29, 2015

@davidrpugh

Given that you spent so much time on this code, I wanted to give you a chance to decide what should go into these method for the classes you wrote. Thus, I have left the following classes without these methods for now:

  • Model (in model.py)
  • CESModel (in ces.py)
  • CobbDouglassModel (in cobb_douglass.py)
  • ImpulseResponse (in impulse_response.py)
  • IVP (in ivp.py)

Please let me know if you would like to write these methods yourself if you want me to try to figure out something reasonable.

Thanks!

@sglyon
Copy link
Member Author

sglyon commented Jan 29, 2015

At this point we just need to implement the display methods for the classes indicated in the checklist in the previous comment to @davidrpugh . All other classes are ready to go.

So, once we have finished with those, this PR should be ready to merge.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.67%) to 91.54% when pulling 6e5e83d on repr into 26bc87e on master.

@davidrpugh
Copy link
Contributor

@spencerlyon2

Thanks for the heads up. I will look at this later this evening.

@davidrpugh
Copy link
Contributor

@spencerlyon2

I have committed the changes locally and pushed them to my fork of the quantecon repo, but the commits are not showing up here. Somehow the repr branch in my fork seems to have become detached from the repr branch here. Thoughts?

@sglyon
Copy link
Member Author

sglyon commented Jan 30, 2015

Thanks for doing that! That's great

The little note below your comment says Add more commits by pushing to the repr branch on QuantEcon/QuantEcon.py.

I'll just pull changes down from your repo and push to this one.

@davidrpugh
Copy link
Contributor

@spencerlyon2

Weird. I didn't see any such note. In any case I initially tried

git push -u https://github.com/QuantEcon/QuantEcon.py.git/repr

this failed due to insufficient permissions.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.02%) to 91.2% when pulling 57f1b2e on repr into 26bc87e on master.

@davidrpugh
Copy link
Contributor

Also I haven't yet added anything to the IVP class yet. The constructor takes functions as inputs and there aren't any parameters per se. Do you have any ideas?

@sglyon
Copy link
Member Author

sglyon commented Jan 30, 2015

I'm not sure you have push permissions to QuantEcon/QuantEcon.py, that might why that failed. It was the right idea though.

If there really isn't any useful information to print for the ivp class you could leave it without a display method -- I'd be totally fine with that.

@oyamad
Copy link
Member

oyamad commented Jan 30, 2015

@spencerlyon2 Re: DiGraph

Very good, thanks!

@sglyon
Copy link
Member Author

sglyon commented Jan 30, 2015

@jstac I think this is ready.

Feel free to merge when you have had a chance to look over it.

@jstac
Copy link
Contributor

jstac commented Jan 30, 2015

This is really neat, thank you!

@jstac jstac merged commit 57f1b2e into master Jan 30, 2015
@jstac jstac deleted the repr branch January 30, 2015 19:45
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.

5 participants