Skip to content

Commit

Permalink
Fix deprecated np.unicode type (#2035)
Browse files Browse the repository at this point in the history
Until numpy version 1.20.0, numpy.unicode was an alias for str in python3. In 1.20.0, it's fully deprecated and is an int. This is bad and breaks things. This commit drops the np.unicode alias and just uses str, as is advised here:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  • Loading branch information
mckinsel committed Feb 3, 2021
1 parent 90a4ff7 commit 3c0b1d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/common/utils/type_conversion_utils.py
Expand Up @@ -44,7 +44,7 @@ def get_dtype_from_dtype(dtype, array_values=None):
if dtype_name == "bool":
return np.uint8
if dtype_name == "object" and dtype_kind == "O":
return np.unicode
return str
if dtype_name == "category":
return get_dtype_from_dtype(dtype.categories.dtype, array_values)

Expand Down
6 changes: 3 additions & 3 deletions server/test/unit/common/utils/test_type_conversion_utils.py
Expand Up @@ -99,7 +99,7 @@ def test__can_cast_to_int32__int64_with_nans_is_false(self):

def test__get_dtype_of_array__supported_dtypes_return_as_expected(self):
types = [np.float32, np.int32, np.bool_, str]
expected_dtypes = [np.float32, np.int32, np.uint8, np.unicode]
expected_dtypes = [np.float32, np.int32, np.uint8, str]

for test_type_index in range(len(types)):
with self.subTest(
Expand All @@ -110,7 +110,7 @@ def test__get_dtype_of_array__supported_dtypes_return_as_expected(self):

def test__get_dtype_of_array__categories_return_as_expected(self):
array = Series(data=["a", "b", "c"], dtype="category")
expected_dtype = np.unicode
expected_dtype = str

actual_dtype = get_dtype_of_array(array)

Expand Down Expand Up @@ -179,7 +179,7 @@ def test__get_dtypes_and_schemas_of_dataframe__dtype_and_schema_returns_as_expec
category_array = Series(data=["a", "b", "b"], dtype="category")
dataframe = DataFrame({"float_array": float_array, "category_array": category_array})

expected_data_types_dict = {"float_array": np.float32, "category_array": np.unicode}
expected_data_types_dict = {"float_array": np.float32, "category_array": str}
expected_schema_type_hints_dict = {
"float_array": {"type": "float32"},
"category_array": {"type": "categorical", "categories": ["a", "b"]},
Expand Down

0 comments on commit 3c0b1d4

Please sign in to comment.