Skip to content

Commit 3c0b1aa

Browse files
committed
BUG: pandas-dev#31464 Fix error when parsing JSON list of bool into Series
Add a missing exception type to the except clause, to cover the TypeError that is thrown by Cythonized array_to_datetime function when trying to convert bool to nonseconds.
1 parent bd91f45 commit 3c0b1aa

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
@@ -429,6 +429,7 @@ I/O
429429
- Bug in :meth:`read_sas` was raising an ``AttributeError`` when reading files from Google Cloud Storage (issue:`33069`)
430430
- Bug in :meth:`DataFrame.to_sql` where an ``AttributeError`` was raised when saving an out of bounds date (:issue:`26761`)
431431
- Bug in :meth:`read_excel` did not correctly handle multiple embedded spaces in OpenDocument text cells. (:issue:`32207`)
432+
- Bug in :meth:`read_json` was raising ``TypeError`` when reading a list of booleans into a Series. (:issue:`31464`)z
432433

433434
Plotting
434435
^^^^^^^^

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_readlines.py

+6
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,9 @@ def test_readjson_unicode(monkeypatch):
179179
result = read_json(path)
180180
expected = pd.DataFrame({"£©µÀÆÖÞßéöÿ": ["АБВГДабвгд가"]})
181181
tm.assert_frame_equal(result, expected)
182+
183+
184+
def test_readjson_bool_series():
185+
result = read_json("[true, true, false]", typ="series")
186+
expected = pd.Series([True, True, False])
187+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)