-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Refactor old %-formatting to use format() builtin #223
base: main
Are you sure you want to change the base?
Conversation
- With int_format and float_format, allow these to optionally end with alpha char, e.g. 'x' or 'g' - Previously, only float_format optionally ended with 'f'
Codecov Report
@@ Coverage Diff @@
## master #223 +/- ##
==========================================
+ Coverage 94.38% 94.61% +0.22%
==========================================
Files 5 5
Lines 2281 2303 +22
==========================================
+ Hits 2153 2179 +26
+ Misses 128 124 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
Thanks for this! Please could you add/adjust tests to cover the new alpha char endings?
I've added a few different tests for a few different format codes. Not sure if something else was expected, so please note and I can pivot the last commit. |
Additional tests for invalid formats are added. Note that using "%3d" % 24.6 # ' 24'
format(24.6, "3d") # ValueError: Unknown format code 'd' for object of type 'float' this could have some implications for end-users that have mixed types in a column with either format code. |
That could be a problem, we don't really want to introduce breaking changes here. |
I'd hate to break things. One solution is to catch an exception, show a warning about mixing datatypes and fallback with Update: I've been trying to make a breaking example, but I can't seem to create one. A field can have mixed types, and a definition for each |
The old
%
-formatting is not ageing well in modern Python code, and has largely been superseded by format strings driven by theformat()
built-in. This PR pivots away from the%
operator when used for string operations.One notable change is to the behaviour of
int_format
andfloat_format
, which have been changed to optionally allowed to end with alpha char, e.g.#08x
or8.3G
. Previously, onlyfloat_format
optionally ended withf
.