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

[Test] Setup test for add_rank_size #519

Closed
mmcky opened this issue Dec 8, 2019 · 5 comments · Fixed by #551
Closed

[Test] Setup test for add_rank_size #519

mmcky opened this issue Dec 8, 2019 · 5 comments · Fixed by #551
Labels

Comments

@mmcky
Copy link
Contributor

mmcky commented Dec 8, 2019

Setup a test for function contributed via PR #518

@mmcky mmcky added the tests label Dec 8, 2019
@shrabian
Copy link

Hey I'd like to take this issue

@bktaha
Copy link
Contributor

bktaha commented Jun 12, 2020

As the author @jstac mentions in the PR, the method is written as it is so as not to add new external dependencies ( matplotlib ). It takes distribution data and an matplotlib.Axes object as parameter, generates rank_data and size_data and in turn passes those to the Axes object. So there is no return variable, only the Axes object with a changed state. Example usage from docstring :

import matplotlib.pyplot as plt
y = np.exp(np.random.randn(1000))  # simulate data
fig, ax = plt.subplots()
rank_size_plot(y, ax)
plt.show()

In a test then we will need to use get methods of the Axes object to retrieve rank-size data, and verify against a standard output. As I understand this will require adding matplotlib as a dependency, which the author was trying to avoid in the first place.

--

An alternative could be to rewrite this method to take only the distribution data and return rank-size data, using a similar signature as the lorenz_curve() method in the same module. Setting of log scale on the axes, labels and other parameters will have to be done separately like so,

rank_data, size_data = rank_size(y)
ax.loglog(rank_data, size_data, 'o', markersize=3.0, alpha=0.5, label=label)
ax.set_xlabel("log rank")
ax.set_ylabel("log size")
plt.show()

Do the maintainers have thoughts on how to go about this?

Apologies for the long explanation, I tried to convey my approach as I see it. Please add if I am mising something.

@jstac
Copy link
Contributor

jstac commented Jun 12, 2020

@bktaha , I think this is an excellent proposal. It's a better solution and your explanation is very clear.

The only issue is that it will break some code in the lectures. You can find one example in the solution to exercise 2 here: https://python.quantecon.org/wealth_dynamics.html#Exercise-2

Hence it would be necessary to adjust the lectures and the code library at the same time.

The full list of changes that need to be made in the lectures can be found by cloning https://github.com/QuantEcon/lecture-python and searching for the string in /source/rst.

Then we can do a simultaneous merge, and a new release of the library (CC @mmcky).

Might you be willing to take the full task on @bktaha? Or might @shrabian be able to help? (Sorry we missed your message.)

@bktaha
Copy link
Contributor

bktaha commented Jun 13, 2020

Based on this discussion, there are 3 such lectures.

I cross-checked this by searching for the string in the /source/rst directory.

--

I'd be happy to take the full task on.

Should I keep the name rank_size_plot or change it to rank_size or rank_size_curve ?

@jstac
Copy link
Contributor

jstac commented Jun 13, 2020

Thanks @bktaha, that's greatly appreciated.

I'll look forward to reviewing your PRs.

Let's go for rank_size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants