[python-package] removed _json_default_with_numpy private function #7145
+2
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi 👋 ,
I believe this private function should be removed instead of tested.
_json_default_with_numpy,model_to_stringhere anddump_modelhere .json.dumps(self.pandas_categorical, default=_json_default_with_numpy).self.pandas_categoricalis only value other thanNoneif theXdata argument is given as a a pandas DataFrame here.np.bool_,np.floating, andnp.integerthat are in theisinstance()if condition in_json_default_with_numpyhere can all be converted to their appropriate python types resulting inself.pandas_categorical = None->self.pandas_categorical = {}. This is possible because Pandas automatically converts NumPy scalars to pandas dtypes during DataFrame construction of the DataFrame._json_default_with_numpyregardingnp.ndarrayhere is not reachable in the code because it is not allow dtype for a pandas DataFrame based on the instilled checks.data used:
I also checked
_json_default_with_numpyby manually inputting aself.pandas_categoricalthat actually invokes the function.which results in a model dump json pandas categorical key value pair
pandas_categorical:{"feature_index": 0, "test_np_bool": true, "test_np_int64": 42, "test_np_array": [1, 2, 3]}However, as explained before it is not possible for self.pandas_categorical to have a value like this.
If I am wrong please explain to me what I am missing 😃