Skip to content

CLN FloatArrayFormatter #12194

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
wants to merge 1 commit into from
Closed

CLN FloatArrayFormatter #12194

wants to merge 1 commit into from

Conversation

nbonnotte
Copy link
Contributor

I'm working on #12164

This is a work in progress.

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string Clean labels Feb 1, 2016
@nbonnotte nbonnotte changed the title WIP: CLN FloatArrayFormatter CLN FloatArrayFormatter Feb 2, 2016
@nbonnotte
Copy link
Contributor Author

Ok, that should do.

What I have done:

  • Instead of differentiating on the one hand FloatArrayFormatter.get_result (which comes from GenericArrayFormatter), and on the other hand FloatArrayFormatter.get_formated_data, according to their destination (two usages, two functions, two independent pieces of code), I differentiate with the type of the output: .get_result keeps returning a list like before, and the new .get_result_as_array returns a numpy array like .get_formatted_data used to.
  • The question "do we want a fixed-width output?", which is a formatting question, is translated like all formatting matters into a parameter fixed_width for the GenericArrayFormatter constructor (boolean, default True, because that's the main usage as of today)

This seems (to me) the simplest way to know which method should be used.

I have merged the two independent pieces of code that we used to have, and which were doing basically the same thing. But FloatArrayFormatter.get_formated_data was more refined, as it was using a mask to deal separately with the NaN values. I've kept that approach, but I don't know if it is the best option in term of performances.

# separate the wheat from the chaff
values = self.values
mask = isnull(values)
if hasattr(values, 'to_dense'): # sparse array
Copy link
Contributor

Choose a reason for hiding this comment

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

you can always call this, to_dense() is a generic method (doesn't do anything to non-dense things)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AttributeError: 'numpy.ndarray' object has no attribute 'to_dense'

:)

@nbonnotte
Copy link
Contributor Author

All green

@jreback
Copy link
Contributor

jreback commented Feb 12, 2016

this looked ok last time. pls rebase and repush.

@nbonnotte
Copy link
Contributor Author

@jreback all set

@jreback
Copy link
Contributor

jreback commented Feb 13, 2016

does this actually change any features? e.g. implement the decimal fix? (or is that another PR), this just cleanup?

@jreback jreback added this to the 0.18.0 milestone Feb 13, 2016
@jreback jreback closed this in 2d51b33 Feb 13, 2016
@jreback
Copy link
Contributor

jreback commented Feb 13, 2016

thanks!

@nbonnotte nbonnotte deleted the 12164-cleaning-floatarrayformatter branch February 14, 2016 06:44
@nbonnotte
Copy link
Contributor Author

No, that was just a cleanup, that's why I haven't touched the tests. Now I should be able to move on to the decimal parameter (issue #12031)

@nbonnotte nbonnotte restored the 12164-cleaning-floatarrayformatter branch February 22, 2016 11:06
@nbonnotte nbonnotte deleted the 12164-cleaning-floatarrayformatter branch February 22, 2016 11:07
gfyoung added a commit to forking-repos/pandas that referenced this pull request Jun 15, 2016
Float values were being quoted despite the quoting spec.
Bug traced to the float formatting that was unconditionally
casting all floats to string. Unconditional casting traced
back to commit 2d51b33 (pandas-devgh-12194) via bisection. This commit
undoes some of those changes to rectify the behaviour.

Closes pandas-devgh-12922.

[ci skip]
jreback pushed a commit that referenced this pull request Jun 16, 2016
Closes #12922: "bug" traced to #12194

Author: gfyoung <[email protected]>

Closes #13418 from gfyoung/to-csv-quote-bugfix and squashes the following commits:

8e53112 [gfyoung] BUG: Fix quoting behaviour in to_csv for csv.QUOTE_NONNUMERIC
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

Successfully merging this pull request may close these issues.

2 participants