Skip to content

Commit c5e3a60

Browse files
committed
Fix linting errors (line length and code style)
- Break long lines to comply with 88 character limit - Use list comprehension instead of append in loop - Improve code readability with multi-line formatting
1 parent 8667459 commit c5e3a60

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

pandas/core/sorting.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,19 @@ def compress_group_index(
683683
import sys
684684

685685
# Use numpy-based approach for Python 3.14+ to avoid hashtable issues
686-
if sys.version_info >= (3, 14) or (len(group_index) and np.all(group_index[1:] >= group_index[:-1])):
686+
is_sorted = len(group_index) and np.all(
687+
group_index[1:] >= group_index[:-1]
688+
)
689+
if sys.version_info >= (3, 14) or is_sorted:
687690
# GH 53806: fast path for sorted group_index
688691
# GH 63314: also use for Python 3.14+ due to hashtable behavior changes
689692
if len(group_index) == 0:
690-
return ensure_int64(np.array([], dtype=np.int64)), ensure_int64(np.array([], dtype=np.int64))
693+
empty_arr = np.array([], dtype=np.int64)
694+
return ensure_int64(empty_arr), ensure_int64(empty_arr)
691695

692696
# Sort if needed
693697
if not np.all(group_index[1:] >= group_index[:-1]):
694-
sorted_idx = np.argsort(group_index, kind='stable')
698+
sorted_idx = np.argsort(group_index, kind="stable")
695699
sorted_group_index = group_index[sorted_idx]
696700
unsort_idx = np.empty_like(sorted_idx)
697701
unsort_idx[sorted_idx] = np.arange(len(sorted_idx))
@@ -700,7 +704,10 @@ def compress_group_index(
700704
unsort_idx = None
701705

702706
unique_mask = np.concatenate(
703-
[sorted_group_index[:1] > -1, sorted_group_index[1:] != sorted_group_index[:-1]]
707+
[
708+
sorted_group_index[:1] > -1,
709+
sorted_group_index[1:] != sorted_group_index[:-1],
710+
]
704711
)
705712
comp_ids_sorted = unique_mask.cumsum() - 1
706713
obs_group_ids = sorted_group_index[unique_mask]

pandas/tests/reshape/test_pivot.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,19 +2961,16 @@ def test_pivot_empty_dataframe_period_dtype(self, freq):
29612961
tm.assert_frame_equal(result, expected)
29622962

29632963
def test_pivot_table_large_dataset_no_duplicates(self):
2964-
# GH 63314: pivot_table with large datasets should not produce duplicate indices
2965-
# This test ensures that the fix for Python 3.14 hashtable issues works correctly
2964+
# GH 63314: pivot_table with large datasets should not produce
2965+
# duplicate indices. This test ensures the Python 3.14 fix works.
29662966
n_indices = 10000
29672967
metrics = ["apple", "banana", "coconut"]
29682968

2969-
data = []
2970-
for i in range(n_indices):
2971-
for metric in metrics:
2972-
data.append({
2973-
"idx": f"id_{i}",
2974-
"metric": metric,
2975-
"value": i * 10 + len(metric)
2976-
})
2969+
data = [
2970+
{"idx": f"id_{i}", "metric": metric, "value": i * 10 + len(metric)}
2971+
for i in range(n_indices)
2972+
for metric in metrics
2973+
]
29772974

29782975
df = DataFrame(data)
29792976

@@ -2985,15 +2982,19 @@ def test_pivot_table_large_dataset_no_duplicates(self):
29852982
)
29862983

29872984
# Verify no duplicate indices in the result
2988-
assert len(result.index) == len(result.index.unique()), \
2989-
f"Expected {len(result.index.unique())} unique indices, got {len(result.index)}"
2985+
n_unique = len(result.index.unique())
2986+
assert len(result.index) == n_unique, (
2987+
f"Expected {n_unique} unique indices, got {len(result.index)}"
2988+
)
29902989

29912990
# Verify we have the expected number of rows
2992-
assert len(result) == n_indices, \
2991+
assert len(result) == n_indices, (
29932992
f"Expected {n_indices} rows, got {len(result)}"
2993+
)
29942994

29952995
# Verify all expected indices are present
29962996
expected_indices = {f"id_{i}" for i in range(n_indices)}
29972997
actual_indices = set(result.index)
2998-
assert expected_indices == actual_indices, \
2998+
assert expected_indices == actual_indices, (
29992999
"Result indices don't match expected indices"
3000+
)

0 commit comments

Comments
 (0)