Skip to content

Cleaning FloatArrayFormatter #12164

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

Closed
nbonnotte opened this issue Jan 28, 2016 · 3 comments
Closed

Cleaning FloatArrayFormatter #12164

nbonnotte opened this issue Jan 28, 2016 · 3 comments
Labels
Clean Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@nbonnotte
Copy link
Contributor

While working on issue #12031 (adding a decimal parameter to .to_latex() and .to_html()), I realized a solution would be pretty straight-forward if only FloatArrayFormatter was a bit cleaned.

Currently, there are two methods that do a similar work:

  • .get_formatted_data(), which returns the array with its float values converted to strings using the parameters given at initialisation.
  • .get_result(), which does something similar, but with a fixed-width output suitable for screen printing.

The two methods don't share any piece of code.

(The first method can already deal with a decimal parameter. The second cannot, and it is the one used by .to_latex.)

This is in part my fault, since my pull request #11681 could have been more factorized.

Anyway, I'm volunteering to do a PR.

@jreback jreback added the Clean label Jan 28, 2016
@jreback jreback added this to the Next Major Release milestone Jan 28, 2016
@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Jan 28, 2016
@jreback
Copy link
Contributor

jreback commented Jan 28, 2016

sure!

@jreback
Copy link
Contributor

jreback commented Jan 28, 2016

related this this is:

In [1]: s = Series([1,2,3],np.arange(3.))

In [2]: s
Out[2]: 
0    1
1    2
2    3
dtype: int64

In [3]: s.index
Out[3]: Float64Index([0.0, 1.0, 2.0], dtype='float64')

In [4]: s = Series([1,2,3],np.arange(3.)+.01)

In [5]: s
Out[5]: 
0.01    1
1.01    2
2.01    3
dtype: int64

In [6]: s.index
Out[6]: Float64Index([0.01, 1.01, 2.01], dtype='float64')

This is misleading and [2] index should prob be format with a single decimal place
eg
1.0 to make it obvious this is a Float64Index.

the _trim_zeros function is a bit aggressive here.

@nbonnotte
Copy link
Contributor Author

@jreback I'm about to make a separate PR for the _trim_zeros issue

jreback pushed a commit that referenced this issue Feb 5, 2016
@jreback jreback modified the milestones: 0.18.0, Next Major Release Feb 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

2 participants