Skip to content

Commit d857cd1

Browse files
authored
BUG: #31464 Fix error when parsing JSON list of bool into Series (#33373)
1 parent 60d6f28 commit d857cd1

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ I/O
434434
- Bug in :meth:`read_sas` was raising an ``AttributeError`` when reading files from Google Cloud Storage (issue:`33069`)
435435
- Bug in :meth:`DataFrame.to_sql` where an ``AttributeError`` was raised when saving an out of bounds date (:issue:`26761`)
436436
- Bug in :meth:`read_excel` did not correctly handle multiple embedded spaces in OpenDocument text cells. (:issue:`32207`)
437+
- Bug in :meth:`read_json` was raising ``TypeError`` when reading a list of booleans into a Series. (:issue:`31464`)
437438

438439
Plotting
439440
^^^^^^^^

pandas/io/json/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ def _try_convert_to_date(self, data):
982982
for date_unit in date_units:
983983
try:
984984
new_data = to_datetime(new_data, errors="raise", unit=date_unit)
985-
except (ValueError, OverflowError):
985+
except (ValueError, OverflowError, TypeError):
986986
continue
987987
return new_data, True
988988
return data, False

pandas/tests/io/json/test_pandas.py

+6
Original file line numberDiff line numberDiff line change
@@ -1659,3 +1659,9 @@ def test_json_pandas_nulls(self, nulls_fixture):
16591659
# GH 31615
16601660
result = pd.DataFrame([[nulls_fixture]]).to_json()
16611661
assert result == '{"0":{"0":null}}'
1662+
1663+
def test_readjson_bool_series(self):
1664+
# GH31464
1665+
result = read_json("[true, true, false]", typ="series")
1666+
expected = pd.Series([True, True, False])
1667+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)