(datetime_array, engine, pretty)
| 181 | |
| 182 | |
| 183 | def test_datetime_arrays(datetime_array, engine, pretty): |
| 184 | value = build_test_dict(datetime_array) |
| 185 | result = pio.to_json_plotly(value, engine=engine) |
| 186 | |
| 187 | def to_str(v): |
| 188 | try: |
| 189 | v = v.isoformat(sep="T") |
| 190 | except (TypeError, AttributeError): |
| 191 | pass |
| 192 | |
| 193 | return str(v) |
| 194 | |
| 195 | if isinstance(datetime_array, list): |
| 196 | dt_values = [to_str(d) for d in datetime_array] |
| 197 | elif isinstance(datetime_array, pd.Series): |
| 198 | with warnings.catch_warnings(): |
| 199 | warnings.simplefilter("ignore", FutureWarning) |
| 200 | # Series.dt.to_pydatetime will return Index[object] |
| 201 | # https://github.com/pandas-dev/pandas/pull/52459 |
| 202 | dt_values = [ |
| 203 | to_str(d) for d in np.array(datetime_array.dt.to_pydatetime()).tolist() |
| 204 | ] |
| 205 | elif isinstance(datetime_array, pd.DatetimeIndex): |
| 206 | dt_values = [to_str(d) for d in datetime_array.to_pydatetime().tolist()] |
| 207 | else: # numpy datetime64 array |
| 208 | dt_values = [to_str(d) for d in datetime_array] |
| 209 | |
| 210 | array_str = to_json_test(dt_values) |
| 211 | expected = build_test_dict_string(array_str) |
| 212 | if orjson: |
| 213 | # orjson always serializes datetime64 to ns, but json will return either |
| 214 | # full seconds or microseconds, if the rest is zeros. |
| 215 | # we don't care about any trailing zeros |
| 216 | trailing_zeros = re.compile(r'[.]?0+"') |
| 217 | result = trailing_zeros.sub('"', result) |
| 218 | expected = trailing_zeros.sub('"', expected) |
| 219 | |
| 220 | assert result == expected |
| 221 | check_roundtrip(result, engine=engine, pretty=pretty) |
| 222 | |
| 223 | |
| 224 | def test_object_array(engine, pretty): |
nothing calls this directly
no test coverage detected