Skip to content

Commit 9251283

Browse files
committed
Fix ruff fomatting, linting, namespace issues using pre-commit hooks
1 parent d02a7a2 commit 9251283

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ I/O
697697
- Bug in :meth:`.DataFrame.to_json` when ``"index"`` was a value in the :attr:`DataFrame.column` and :attr:`Index.name` was ``None``. Now, this will fail with a ``ValueError`` (:issue:`58925`)
698698
- Bug in :meth:`DataFrame._repr_html_` which ignored the ``"display.float_format"`` option (:issue:`59876`)
699699
- Bug in :meth:`DataFrame.from_records` where ``columns`` parameter with numpy structured array was not reordering and filtering out the columns (:issue:`59717`)
700-
- Bug in :meth:`DataFrame.to_csv` where `quoting=csv.QUOTE_NONNUMERIC` adds extra decimal places when ``dtype=float32``, ``dtype=float16`` and ``float_format=None`` in the csv output (:issue:`60699`)
700+
- Bug in :meth:`DataFrame.to_csv` where ``quoting=csv.QUOTE_NONNUMERIC`` adds extra decimal places when ``dtype=float32``, ``dtype=float16`` and ``float_format=None`` in the csv output (:issue:`60699`)
701701
- Bug in :meth:`DataFrame.to_dict` raises unnecessary ``UserWarning`` when columns are not unique and ``orient='tight'``. (:issue:`58281`)
702702
- Bug in :meth:`DataFrame.to_excel` when writing empty :class:`DataFrame` with :class:`MultiIndex` on both axes (:issue:`57696`)
703703
- Bug in :meth:`DataFrame.to_excel` where the :class:`MultiIndex` index with a period level was not a date (:issue:`60099`)

pandas/core/indexes/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7756,11 +7756,12 @@ def get_values_for_csv(
77567756
mask = isna(values)
77577757

77587758
# GH60699
7759-
# Ensure quoting don't add extra decimal places in output for float16, float32
7759+
# Ensure quoting don't add extra decimal places in output
7760+
# for float16, float32
77607761
if values.dtype in [np.float16, np.float32]:
7761-
values = np.array(values, dtype="str")
7762-
values = values.astype(float, copy=False)
7763-
7762+
values = np.array(values, dtype="str")
7763+
values = values.astype(float, copy=False)
7764+
77647765
values = values.astype(object, copy=False)
77657766
values[mask] = na_rep
77667767
return values

pandas/tests/frame/methods/test_to_csv.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,37 +1316,68 @@ def test_to_csv_quoting(self):
13161316
expected = tm.convert_rows_list_to_csv_str(expected_rows)
13171317
assert df.to_csv(quoting=csv.QUOTE_ALL) == expected
13181318

1319-
@pytest.mark.parametrize("data, dtype, expected_rows",
1319+
@pytest.mark.parametrize(
1320+
"data, dtype, expected_rows",
13201321
[
13211322
# Test Case 1: float16 precision
13221323
(
13231324
{"col": [8.57, 0.156, -0.312, 123.3, -54.5, np.nan]},
13241325
"float16",
1325-
['"","col"', '0,8.57', '1,0.156', '2,-0.312', '3,123.3', '4,-54.5', '5,""']
1326+
[
1327+
'"","col"',
1328+
"0,8.57",
1329+
"1,0.156",
1330+
"2,-0.312",
1331+
"3,123.3",
1332+
"4,-54.5",
1333+
'5,""',
1334+
],
13261335
),
1327-
13281336
# Test Case 2: float32 precision
13291337
(
1330-
{"col": [8.57, 1.234567, -2.345678, 1e6, -1.5e6, np.nan]},
1338+
{"col": [8.57, 1.234567, -2.345678, 1e6, -1.5e6, np.nan]},
13311339
"float32",
1332-
['"","col"', '0,8.57', '1,1.234567', '2,-2.345678', '3,1000000.0', '4,-1500000.0', '5,""']
1340+
[
1341+
'"","col"',
1342+
"0,8.57",
1343+
"1,1.234567",
1344+
"2,-2.345678",
1345+
"3,1000000.0",
1346+
"4,-1500000.0",
1347+
'5,""',
1348+
],
13331349
),
1334-
13351350
# Test Case 3: float64 precision
13361351
(
1337-
{"col": [8.57, 3.141592653589793, -2.718281828459045, 1.01e12, -5.67e11, np.nan]},
1352+
{
1353+
"col": [
1354+
8.57,
1355+
3.141592653589793,
1356+
-2.718281828459045,
1357+
1.01e12,
1358+
-5.67e11,
1359+
np.nan,
1360+
]
1361+
},
13381362
"float64",
1339-
['"","col"', '0,8.57', '1,3.141592653589793', '2,-2.718281828459045',
1340-
'3,1010000000000.0', '4,-567000000000.0', '5,""']
1363+
[
1364+
'"","col"',
1365+
"0,8.57",
1366+
"1,3.141592653589793",
1367+
"2,-2.718281828459045",
1368+
"3,1010000000000.0",
1369+
"4,-567000000000.0",
1370+
'5,""',
1371+
],
13411372
),
1342-
]
1373+
],
13431374
)
13441375
def test_to_csv_decimal_and_nonnumeric_quoting(self, data, dtype, expected_rows):
13451376
# https://github.com/pandas-dev/pandas/issues/60699
1346-
# combination of float dtype, no special formatting and
1377+
# combination of float dtype, no special formatting and
13471378
# quoting is specified (quoting=csv.QUOTE_NONNUMERIC)
1348-
df = pd.DataFrame(data, dtype=dtype)
1349-
result = df.to_csv(quoting=csv.QUOTE_NONNUMERIC)
1379+
df = DataFrame(data, dtype=dtype)
1380+
result = df.to_csv(quoting=csv.QUOTE_NONNUMERIC)
13501381
expected = tm.convert_rows_list_to_csv_str(expected_rows)
13511382
assert result == expected
13521383

0 commit comments

Comments
 (0)