drf_orjson_renderer icon indicating copy to clipboard operation
drf_orjson_renderer copied to clipboard

Removes DjangoNumpyJSONEncoder (breaking change)

Open radusuciu opened this issue 6 months ago • 0 comments

As suggested in https://github.com/brianjbuck/drf_orjson_renderer/pull/24, DjangoNumpyJSONEncoder should no longer be necessary when using orjson 3.3 or newer. This fixes an issue when this package is used with numpy 2.0, which has removed np.float_. However, since we'd be removing existing functionality, I think this has to be a breaking change. I did not update the version, but I guess this should probably mean going to 2.0.0.

@DanyilVoloshchuk, That would be a better solution than the original one proposed. You really shouldn't need it however since v3.3 orjson supports both numpy versions out of the box. That encoder was written before orjson supported numpy and only exists for some backwards compatibility before everyone upgraded orjson versions.

My preferred solution would be to remove the DjangoNumpyJSONEncoder entirely and have everyone migrate away from using that encoder. The docs could probably be more clear that developers should be using the orjson options instead:

REST_FRAMEWORK = {
    "ORJSON_RENDERER_OPTIONS": (
        orjson.OPT_SERIALIZE_NUMPY,
    ),
}

radusuciu avatar Aug 27 '24 18:08 radusuciu