Skip to content

Commit 38dbc89

Browse files
committed
update unit tests
1 parent ec065bf commit 38dbc89

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/unit/test_json.py

+21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516

1617
import numpy as np
1718
import pandas as pd
@@ -85,6 +86,12 @@ def test_deterministic_json_serialization():
8586

8687

8788
def test_to_numpy():
89+
"""
90+
Verifies that JSONArray can be cast to a NumPy array.
91+
This test ensures compatibility with Python 3.9 and replicates the behavior
92+
of the `test_to_numpy` test from `test_json_compliance.py::TestJSONArrayCasting`,
93+
which is run with Python 3.12 environments only.
94+
"""
8895
data = db_dtypes.JSONArray._from_sequence(JSON_DATA.values())
8996
expected = np.asarray(data)
9097

@@ -93,3 +100,17 @@ def test_to_numpy():
93100

94101
result = pd.Series(data).to_numpy()
95102
pd._testing.assert_equal(result, expected)
103+
104+
105+
def test_as_numpy_array():
106+
data = db_dtypes.JSONArray._from_sequence(JSON_DATA.values())
107+
result = np.asarray(data)
108+
expected = np.asarray(
109+
[
110+
json.dumps(value, sort_keys=True, separators=(",", ":"))
111+
if value is not None
112+
else pd.NA
113+
for value in JSON_DATA.values()
114+
]
115+
)
116+
pd._testing.assert_equal(result, expected)

0 commit comments

Comments
 (0)