-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: extra leading space in to_string when index=False #29670
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
BUG: extra leading space in to_string when index=False #29670
Conversation
pandas/io/formats/format.py
Outdated
@@ -1095,7 +1106,7 @@ def format_array( | |||
space: Optional[Union[str, int]] = None, | |||
justify: str = "right", | |||
decimal: str = ".", | |||
leading_space: Optional[bool] = None, | |||
leading_space: bool = "compat", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't a boolean? Can you run mypy on your changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yeah, didn't see your comment when I committed my latest change. I changed already
"inputs, expected", | ||
[([" a", " b"], " a\n b"), ([".1", "1"], ".1\n 1"), (["10", "-10"], " 10\n-10")], | ||
) | ||
def test_to_string_index_false_corner_case(inputs, expected): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these cases should just be added as param's to your test method below test_format_remove_leading_space_series
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, this was just some corner cases that was found during the previous PR. will move.
@@ -937,13 +943,18 @@ def to_latex( | |||
def _format_col(self, i: int) -> List[str]: | |||
frame = self.tr_frame | |||
formatter = self._get_formatter(i) | |||
if self.index: | |||
leading_space = "compat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there was already some discussion around this here https://github.com/pandas-dev/pandas/pull/25000/files#r252237505 -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm, i think i addressed it already in this PR?
@@ -1110,7 +1121,7 @@ def format_array( | |||
space | |||
justify | |||
decimal | |||
leading_space : bool, optional | |||
leading_space : bool, default is 'compat' | |||
Whether the array should be formatted with a leading space. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as previous here what is the intended type of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I didn't notice this so just copy paste the change in my previous PR. my bad, changed.
thanks for the pr @charlesdong1991 - some comments above. We can re-open the previous PR if helpful? #25000 |
thanks for your comment, @alimcmaster1 |
Finally the annotation error is gone, it's green now 😅 pls take a look and see if this PR is useful. |
Hello, @jreback All comments in the last closed PR were addressed. |
So, this PR seems ok. Anyone with the right permissions to fix conflict an merge? I've been forced to keep using version |
@simontorres there are quite a number of comments on this i find it hard to believe this blocking an update of pandas |
I was talking out ignorance. I'm sorry |
Hi, @simontorres i resolved the conflict, and as @jreback said, there are some comments in the PR, and pls feel free to take over if you could find a better solution for this, and then i could close this PR to make way for you! |
Thanks @charlesdong1991 and @jreback . I don't think I can find a better solution but I will see if I can help. |
I am sure you could help with the issue and pandas 👍 @simontorres also @jreback feel free to close this PR if you find it hard to approach! |
@simontorres |
Introduction/ApplicationOne example is this Imaging Spectrograph called GoodmanHTS, there are two elements that can move a camera and a dispersor, their angle are recorded in the image's header. There are certain named modes that I'm interested in that can be used define file names, for instance. So this is a shorter version of a longer table. import pandas
columns = ['grating_freq', 'wavmode', 'camtarg', 'grttarg', 'ob_filter']
spec_mode = [['400', 'm1', '11.6', '5.8', 'None'],
['400', 'm2', '16.1', '7.5', 'GG455'],
['600', 'UV', '15.25', '7.0', 'None'],
['600', 'Blue', '17.0', '7.0', 'None'],
['600', 'Mid', '20.0', '10.0', 'GG385'],
['600', 'Red', '27.0', '12.0', 'GG495'],
['930', 'm1', '20.6', '10.3', 'None'],
['930', 'm2', '25.2', '12.6', 'None'],
['930', 'm3', '29.9', '15.0', 'GG385'],
['930', 'm4', '34.6', '18.3', 'GG495'],
['930', 'm5', '39.4', '19.7', 'GG495']]
modes_data_frame = pandas.DataFrame(spec_mode, columns=columns) The problemThe information I get is the Grating Frequency (for instance 930), the Camera Target Angle (camtarg, 20.6), the Grating Target Angle (grttarg, 10.3) and the Order Blocking Filter (. When I use pandas to find the match in the following way. mode = modes_data_frame[
((modes_data_frame['grating_freq'] == 930) &
(modes_data_frame['camtarg'] == 20.6) &
(modes_data_frame['grttarg'] == 10.3) &
(modes_data_frame['ob_filter'] == None))]
if mode.empty:
central_wavelength = get_central_wavelength(*some_args)
return 'Custom_{:d}nm'.format(central_wavelength)
else:
return mode['wavmode'].to_string(index=False) it should return 'm1' instead it returns ' m1' |
This hasn't gotten traction in a while so closing as stale, but @charlesdong1991 or @simontorres ping if you plan to pick up and can continue from there |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
I still see people posting issue for the change of behaviour in
to_string(index=False)
on pandas such as #28538 , so I think it might be worth it to reopen my previous stalled PR #25000 and see if could get it solved this time.All the changes have been made based on the reviews in PR #25000 and for detailed summary and explanation, please check #25000 (comment)
Feel free to take a look and any review and comments are very welcomed!