-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: repr of Categorical does not distinguish int and str. #34222
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
Changes from 16 commits
aaf4e42
1f90a62
5a93a67
4cef20c
a3c6eda
9277d38
b978bf9
3215936
e6ce96f
197038b
f594fa1
4912ec3
79dd24b
d57ae96
aa62a24
9562313
457abe3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
""" | ||
|
||
from contextlib import contextmanager | ||
from csv import QUOTE_NONE, QUOTE_NONNUMERIC | ||
from datetime import tzinfo | ||
import decimal | ||
from functools import partial | ||
|
@@ -176,6 +177,7 @@ def __init__( | |
self.na_rep = na_rep | ||
self.length = length | ||
self.footer = footer | ||
self.quoting = QUOTE_NONNUMERIC | ||
|
||
def _get_footer(self) -> str: | ||
footer = "" | ||
|
@@ -200,6 +202,7 @@ def _get_formatted_values(self) -> List[str]: | |
None, | ||
float_format=None, | ||
na_rep=self.na_rep, | ||
quoting=self.quoting, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quoting always QUOTE_NONNUMERIC |
||
) | ||
|
||
def to_string(self) -> str: | ||
|
@@ -1109,6 +1112,7 @@ def format_array( | |
justify: str = "right", | ||
decimal: str = ".", | ||
leading_space: Optional[bool] = None, | ||
quoting: Optional[int] = None, | ||
) -> List[str]: | ||
""" | ||
Format an array for printing. | ||
|
@@ -1171,6 +1175,7 @@ def format_array( | |
justify=justify, | ||
decimal=decimal, | ||
leading_space=leading_space, | ||
quoting=quoting, | ||
) | ||
|
||
return fmt_obj.get_result() | ||
|
@@ -1216,11 +1221,15 @@ def _format_strings(self) -> List[str]: | |
else: | ||
float_format = self.float_format | ||
|
||
formatter = ( | ||
self.formatter | ||
if self.formatter is not None | ||
else (lambda x: pprint_thing(x, escape_chars=("\t", "\r", "\n"))) | ||
) | ||
if self.formatter is not None: | ||
formatter = self.formatter | ||
else: | ||
quote_strings = self.quoting is not None and self.quoting != QUOTE_NONE | ||
formatter = partial( | ||
pprint_thing, | ||
escape_chars=("\t", "\r", "\n"), | ||
quote_strings=quote_strings, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as the ternary expression is getting more complex, an if else may now be more readable. maybe use partial instead of lambda and maybe move quote_strings assignment inside the relevant if else block. |
||
|
||
def _format(x): | ||
if self.na_rep is not None and is_scalar(x) and isna(x): | ||
|
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.
since you changed this in pandas/io/format.py is it also necessary here?
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.
Yes, it's necessary so that
GenericArrayFormatter
is initialised with it