# Buggy code
def sort_values(  # type: ignore[override]
    self,
    by,
    axis: Axis = 0,
    ascending=True,
    inplace: bool = False,
    kind: str = "quicksort",
    na_position: str = "last",
    ignore_index: bool = False,
    key: ValueKeyFunc = None,
):
    inplace = validate_bool_kwarg(inplace, "inplace")
    axis = self._get_axis_number(axis)

    if not isinstance(by, list):
        by = [by]
    if is_sequence(ascending) and len(by) != len(ascending):
        raise ValueError(
            f"Length of ascending ({len(ascending)}) != length of by ({len(by)})"
        )
    if len(by) > 1:
        keys = [self._get_label_or_level_values(x, axis=axis) for x in by]

        # need to rewrap columns in Series to apply key function
        if key is not None:
            keys = [Series(k, name=name) for (k, name) in zip(keys, by)]

        indexer = lexsort_indexer(
            keys, orders=ascending, na_position=na_position, key=key
        )
        indexer = ensure_platform_int(indexer)
    else:
        by = by[0]
        k = self._get_label_or_level_values(by, axis=axis)

        # need to rewrap column in Series to apply key function
        if key is not None:
            k = Series(k, name=by)

        if isinstance(ascending, (tuple, list)):
            ascending = ascending[0]

        indexer = nargsort(
            k, kind=kind, ascending=ascending, na_position=na_position, key=key
        )

    new_data = self._mgr.take(
        indexer, axis=self._get_block_manager_axis(axis), verify=False
    )

    if ignore_index:
        new_data.set_axis(1, ibase.default_index(len(indexer)))

    result = self._constructor(new_data)
    if inplace:
        return self._update_inplace(result)
    else:
        return result.__finalize__(self, method="sort_values")


# Traceback (ValueError)
Traceback (most recent call last):
File "sort_values_test6.py", line 19, in <module>
print(df2)
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 803, in __repr__
self.to_string(
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/frame.py", line 939, in to_string
return fmt.DataFrameRenderer(formatter).to_string(
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/io/formats/format.py", line 1031, in to_string
string = string_formatter.to_string()
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/io/formats/string.py", line 23, in to_string
text = self._get_string_representation()
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/io/formats/string.py", line 47, in _get_string_representation
return self._fit_strcols_to_terminal_width(strcols)
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/io/formats/string.py", line 179, in _fit_strcols_to_terminal_width
self.fmt.truncate()
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/io/formats/format.py", line 700, in truncate
self._truncate_horizontally()
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/io/formats/format.py", line 718, in _truncate_horizontally
self.tr_frame = concat((left, right), axis=1)
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/reshape/concat.py", line 298, in concat
return op.get_result()
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/reshape/concat.py", line 520, in get_result
new_data = concatenate_block_managers(
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/internals/concat.py", line 89, in concatenate_block_managers
return BlockManager(blocks, axes)
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 143, in __init__
self._verify_integrity()
File "/localdisk/gashiman/miniconda3/lib/python3.8/site-packages/pandas/core/internals/managers.py", line 323, in _verify_integrity
raise construction_error(tot_items, block.shape[1:], self.axes)
ValueError: Shape of passed values is (4, 16), indices imply (32, 16)

# Fixed code
def sort_values(  # type: ignore[override]
    self,
    by,
    axis: Axis = 0,
    ascending=True,
    inplace: bool = False,
    kind: str = "quicksort",
    na_position: str = "last",
    ignore_index: bool = False,
    key: ValueKeyFunc = None,
):
    inplace = validate_bool_kwarg(inplace, "inplace")
    axis = self._get_axis_number(axis)

    if not isinstance(by, list):
        by = [by]
    if is_sequence(ascending) and len(by) != len(ascending):
        raise ValueError(
            f"Length of ascending ({len(ascending)}) != length of by ({len(by)})"
        )
    if len(by) > 1:
        keys = [self._get_label_or_level_values(x, axis=axis) for x in by]

        # need to rewrap columns in Series to apply key function
        if key is not None:
            keys = [Series(k, name=name) for (k, name) in zip(keys, by)]

        indexer = lexsort_indexer(
            keys, orders=ascending, na_position=na_position, key=key
        )
        indexer = ensure_platform_int(indexer)
    else:
        by = by[0]
        k = self._get_label_or_level_values(by, axis=axis)

        # need to rewrap column in Series to apply key function
        if key is not None:
            k = Series(k, name=by)

        if isinstance(ascending, (tuple, list)):
            ascending = ascending[0]

        indexer = nargsort(
            k, kind=kind, ascending=ascending, na_position=na_position, key=key
        )

    new_data = self._mgr.take(
        indexer, axis=self._get_block_manager_axis(axis), verify=False
    )

    if ignore_index:
        new_data.set_axis(
            self._get_block_manager_axis(axis), ibase.default_index(len(indexer))
        )

    result = self._constructor(new_data)
    if inplace:
        return self._update_inplace(result)
    else:
        return result.__finalize__(self, method="sort_values")