Skip to content

Commit 96fab69

Browse files
committed
Removed convert skip_false and --skip-false, closes #542
1 parent fafa966 commit 96fab69

File tree

8 files changed

+12
-26
lines changed

8 files changed

+12
-26
lines changed

docs/cli-reference.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ See :ref:`cli_convert`.
653653
--output-type [integer|float|blob|text]
654654
Column type to use for the output column
655655
--drop Drop original column afterwards
656-
--no-skip-false Don't skip falsey values
657656
-s, --silent Don't show a progress bar
658657
--pdb Open pdb debugger on first error
659658
-h, --help Show this message and exit.

docs/cli.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,8 +1711,6 @@ You can include named parameters in your where clause and populate them using on
17111711
17121712
The ``--dry-run`` option will output a preview of the conversion against the first ten rows, without modifying the database.
17131713

1714-
By default any rows with a falsey value for the column - such as ``0`` or ``null`` - will be skipped. Use the ``--no-skip-false`` option to disable this behaviour.
1715-
17161714
.. _cli_convert_import:
17171715

17181716
Importing additional modules

docs/python-api.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,6 @@ This will add the new column, if it does not already exist. You can pass ``outpu
10091009

10101010
If you want to drop the original column after saving the results in a separate output column, pass ``drop=True``.
10111011

1012-
By default any rows with a falsey value for the column - such as ``0`` or ``None`` - will be skipped. Pass ``skip_false=False`` to disable this behaviour.
1013-
10141012
You can create multiple new columns from a single input column by passing ``multi=True`` and a conversion function that returns a Python dictionary. This example creates new ``upper`` and ``lower`` columns populated from the single ``title`` column:
10151013

10161014
.. code-block:: python

sqlite_utils/cli.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,6 @@ def _generate_convert_help():
29522952
type=click.Choice(["integer", "float", "blob", "text"]),
29532953
)
29542954
@click.option("--drop", is_flag=True, help="Drop original column afterwards")
2955-
@click.option("--no-skip-false", is_flag=True, help="Don't skip falsey values")
29562955
@click.option("-s", "--silent", is_flag=True, help="Don't show a progress bar")
29572956
@click.option("pdb_", "--pdb", is_flag=True, help="Open pdb debugger on first error")
29582957
def convert(
@@ -2968,7 +2967,6 @@ def convert(
29682967
output,
29692968
output_type,
29702969
drop,
2971-
no_skip_false,
29722970
silent,
29732971
pdb_,
29742972
):
@@ -3045,7 +3043,6 @@ def wrapped_fn(value):
30453043
output=output,
30463044
output_type=output_type,
30473045
drop=drop,
3048-
skip_false=not no_skip_false,
30493046
multi=multi,
30503047
show_progress=not silent,
30513048
)

sqlite_utils/db.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,6 @@ def convert(
29092909
where: Optional[str] = None,
29102910
where_args: Optional[Union[Iterable, dict]] = None,
29112911
show_progress: bool = False,
2912-
skip_false: bool = True,
29132912
):
29142913
"""
29152914
Apply conversion function ``fn`` to every value in the specified columns.
@@ -2952,8 +2951,6 @@ def convert(
29522951

29532952
def convert_value(v):
29542953
bar.update(1)
2955-
if skip_false and not v:
2956-
return v
29572954
return jsonify_if_needed(fn(v))
29582955

29592956
fn_name = fn.__name__

sqlite_utils/recipes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def parsedate(value, dayfirst=False, yearfirst=False, errors=None):
1414
- errors=r.IGNORE to ignore values that cannot be parsed
1515
- errors=r.SET_NULL to set values that cannot be parsed to null
1616
"""
17+
if not value:
18+
return value
1719
try:
1820
return (
1921
parser.parse(value, dayfirst=dayfirst, yearfirst=yearfirst)
@@ -38,6 +40,8 @@ def parsedatetime(value, dayfirst=False, yearfirst=False, errors=None):
3840
- errors=r.IGNORE to ignore values that cannot be parsed
3941
- errors=r.SET_NULL to set values that cannot be parsed to null
4042
"""
43+
if not value:
44+
return value
4145
try:
4246
return parser.parse(value, dayfirst=dayfirst, yearfirst=yearfirst).isoformat()
4347
except parser.ParserError:

tests/test_cli_convert.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_convert_import(test_db_and_path):
8080
db_path,
8181
"example",
8282
"dt",
83-
"return re.sub('O..', 'OXX', value)",
83+
"return re.sub('O..', 'OXX', value) if value else value",
8484
"--import",
8585
"re",
8686
],
@@ -223,7 +223,7 @@ def test_convert_output_column(test_db_and_path, drop):
223223
db_path,
224224
"example",
225225
"dt",
226-
"value.replace('October', 'Spooktober')",
226+
"value.replace('October', 'Spooktober') if value else value",
227227
"--output",
228228
"newcol",
229229
]
@@ -628,14 +628,8 @@ def test_convert_initialization_pattern(fresh_db_and_path):
628628
]
629629

630630

631-
@pytest.mark.parametrize(
632-
"no_skip_false,expected",
633-
(
634-
(True, 1),
635-
(False, 0),
636-
),
637-
)
638-
def test_convert_no_skip_false(fresh_db_and_path, no_skip_false, expected):
631+
def test_convert_handles_falsey_values(fresh_db_and_path):
632+
# Falsey values like 0 should be converted (issue #527)
639633
db, db_path = fresh_db_and_path
640634
args = [
641635
"convert",
@@ -644,12 +638,10 @@ def test_convert_no_skip_false(fresh_db_and_path, no_skip_false, expected):
644638
"x",
645639
"-",
646640
]
647-
if no_skip_false:
648-
args.append("--no-skip-false")
649641
db["t"].insert_all([{"x": 0}, {"x": 1}])
650642
assert db["t"].get(1)["x"] == 0
651643
assert db["t"].get(2)["x"] == 1
652644
result = CliRunner().invoke(cli.cli, args, input="value + 1")
653645
assert result.exit_code == 0, result.output
654-
assert db["t"].get(1)["x"] == expected
646+
assert db["t"].get(1)["x"] == 1
655647
assert db["t"].get(2)["x"] == 2

tests/test_convert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ def test_convert_where(fresh_db, where, where_args):
5050
assert list(table.rows) == [{"id": 1, "title": "One"}, {"id": 2, "title": "TWO"}]
5151

5252

53-
def test_convert_skip_false(fresh_db):
53+
def test_convert_handles_falsey_values(fresh_db):
54+
# Falsey values like 0 should be converted (issue #527)
5455
table = fresh_db["table"]
5556
table.insert_all([{"x": 0}, {"x": 1}])
5657
assert table.get(1)["x"] == 0
5758
assert table.get(2)["x"] == 1
58-
table.convert("x", lambda x: x + 1, skip_false=False)
59+
table.convert("x", lambda x: x + 1)
5960
assert table.get(1)["x"] == 1
6061
assert table.get(2)["x"] == 2
6162

0 commit comments

Comments
 (0)