Skip to content

OSError when sorting specific string values #316

@AnneWendt

Description

@AnneWendt

Hello,

I think I may have encountered a bug in the sorting function.
We are using tksheet 7.5.17 with Python 3.14 on Windows 11 (with PyCharm IDE 2025.1).

Our data consists of several columns of string values and one of these columns contains numbers saved as strings. There is one entry "115000" that causes an uncaught OSError when calling sheet.sort_rows_by_column() because it gets converted to the date Jan 1st 5000 and then the timestamp() function crashes, presumably because that year is too far away:

  File "C:\Python\3.14.0_64Bit\Lib\site-packages\tksheet\sorting.py", line 166, in natural_sort_key
    return (4, datetime.strptime(item, date_format).timestamp())
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
OSError: [Errno 22] Invalid argument

This happens for item = "115000" and date_format = "%d%m%Y". Is there maybe a way to designate a column as number column so that the date conversion gets skipped? As a temporary solution, I have commented out this particular date format from the list of date formats and it sorts all values just fine.

Kind regards

An avid user of your really useful package

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions