Skip to content

Commit 5a2f9fc

Browse files
Changed the code for failing test cases
1 parent 68b3e83 commit 5a2f9fc

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

pandas/io/formats/css.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@
1919
Iterator,
2020
)
2121

22+
def _normalize_number_format_value(value: str) -> str:
23+
"""
24+
Lowercase number-format value except for text inside double quotes.
25+
26+
This preserves case for string literals (e.g. "M") while still
27+
normalizing things like [Red] -> [red].
28+
"""
29+
value = value.strip()
30+
out: list[str] = []
31+
in_string = False
32+
33+
for ch in value:
34+
if ch == '"':
35+
out.append(ch)
36+
in_string = not in_string
37+
else:
38+
if in_string:
39+
out.append(ch) # preserve case inside string literals
40+
else:
41+
out.append(ch.lower()) # normalize outside literals
42+
return "".join(out)
43+
2244

2345
def _side_expander(prop_fmt: str) -> Callable:
2446
"""
@@ -392,7 +414,7 @@ def atomize(self, declarations: Iterable) -> Generator[tuple[str, str]]:
392414
for prop, value in declarations:
393415
prop = prop.lower()
394416
if prop == "number-format":
395-
value = value.strip()
417+
value = _normalize_number_format_value(value)
396418
else:
397419
value = value.lower()
398420
if prop in self.CSS_EXPANSIONS:
@@ -418,7 +440,7 @@ def parse(self, declarations_str: str) -> Iterator[tuple[str, str]]:
418440
prop = prop.strip().lower()
419441
# TODO: don't lowercase case sensitive parts of values (strings)
420442
if prop == "number-format":
421-
val = val.strip()
443+
val = _normalize_number_format_value(val)
422444
else:
423445
val = val.strip().lower()
424446
if sep:

0 commit comments

Comments
 (0)