Skip to content

Commit 6eab0e4

Browse files
committed
Avoid some FutureWarnings and DeprecationWarnings
1 parent 3dbe753 commit 6eab0e4

File tree

9 files changed

+12
-14
lines changed

9 files changed

+12
-14
lines changed

src/datasets/arrow_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def _get_output_signature(
280280
else:
281281
np_arrays.append(np.array(array))
282282

283-
if np.issubdtype(np_arrays[0].dtype, np.integer) or np_arrays[0].dtype == np.bool:
283+
if np.issubdtype(np_arrays[0].dtype, np.integer) or np_arrays[0].dtype == bool:
284284
tf_dtype = tf.int64
285285
np_dtype = np.int64
286286
elif np.issubdtype(np_arrays[0].dtype, np.number):
@@ -3663,7 +3663,7 @@ def _feature(values: Union[float, int, str, np.ndarray]) -> "tf.train.Feature":
36633663
return _float_feature([values.item()])
36643664
elif np.issubdtype(values.dtype, np.integer):
36653665
return _int64_feature([values.item()])
3666-
elif np.issubdtype(values.dtype, np.str):
3666+
elif np.issubdtype(values.dtype, str):
36673667
return _bytes_feature([values.item().encode()])
36683668
else:
36693669
raise ValueError(f"values={values} has dtype {values.dtype}, which cannot be serialized")

src/datasets/features/features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def __getitem__(self, item: Union[int, slice, np.ndarray]) -> Union[np.ndarray,
810810
def take(
811811
self, indices: Sequence_[int], allow_fill: bool = False, fill_value: bool = None
812812
) -> "PandasArrayExtensionArray":
813-
indices: np.ndarray = np.asarray(indices, dtype=np.int)
813+
indices: np.ndarray = np.asarray(indices, dtype=int)
814814
if allow_fill:
815815
fill_value = (
816816
self.dtype.na_value if fill_value is None else np.asarray(fill_value, dtype=self.dtype.value_type)

src/datasets/formatting/formatting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ def _arrow_array_to_numpy(self, pa_array: pa.Array) -> np.ndarray:
194194
array: List = pa_array.to_numpy(zero_copy_only=zero_copy_only).tolist()
195195
if len(array) > 0:
196196
if any(
197-
(isinstance(x, np.ndarray) and (x.dtype == np.object or x.shape != array[0].shape))
197+
(isinstance(x, np.ndarray) and (x.dtype == object or x.shape != array[0].shape))
198198
or (isinstance(x, float) and np.isnan(x))
199199
for x in array
200200
):
201-
return np.array(array, copy=False, **{**self.np_array_kwargs, "dtype": np.object})
201+
return np.array(array, copy=False, **{**self.np_array_kwargs, "dtype": object})
202202
return np.array(array, copy=False, **self.np_array_kwargs)
203203

204204

src/datasets/formatting/jax_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _recursive_tensorize(self, data_struct: dict):
5454
# support for nested types like struct of list of struct
5555
if isinstance(data_struct, (list, np.ndarray)):
5656
data_struct = np.array(data_struct, copy=False)
57-
if data_struct.dtype == np.object: # jax arrays cannot be instantied from an array of objects
57+
if data_struct.dtype == object: # jax arrays cannot be instantied from an array of objects
5858
return [self.recursive_tensorize(substruct) for substruct in data_struct]
5959
return self._tensorize(data_struct)
6060

src/datasets/formatting/tf_formatter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def _tensorize(self, value):
6565
def _recursive_tensorize(self, data_struct: dict):
6666
# support for nested types like struct of list of struct
6767
if isinstance(data_struct, (list, np.ndarray)):
68-
if (
69-
data_struct.dtype == np.object
70-
): # tensorflow tensors can sometimes be instantied from an array of objects
68+
if data_struct.dtype == object: # tensorflow tensors can sometimes be instantied from an array of objects
7169
try:
7270
return self._tensorize(data_struct)
7371
except ValueError:

src/datasets/formatting/torch_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _recursive_tensorize(self, data_struct: dict):
4646
# support for nested types like struct of list of struct
4747
if isinstance(data_struct, (list, np.ndarray)):
4848
data_struct = np.array(data_struct, copy=False)
49-
if data_struct.dtype == np.object: # pytorch tensors cannot be instantied from an array of objects
49+
if data_struct.dtype == object: # pytorch tensors cannot be instantied from an array of objects
5050
return [self.recursive_tensorize(substruct) for substruct in data_struct]
5151
return self._tensorize(data_struct)
5252

src/datasets/utils/stratify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def approximate_mode(class_counts, n_draws, rng):
4848
need_to_add -= add_now
4949
if need_to_add == 0:
5050
break
51-
return floored.astype(np.int)
51+
return floored.astype(int)
5252

5353

5454
def stratified_shuffle_split_generate_indices(y, n_train, n_test, rng, n_splits=10):

tests/features/test_array_xd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def test_array_xd_with_none():
335335
dummy_array = np.array([[1, 2], [3, 4]], dtype="int32")
336336
dataset = datasets.Dataset.from_dict({"foo": [dummy_array, None, dummy_array]}, features=features)
337337
arr = NumpyArrowExtractor().extract_column(dataset._data)
338-
assert isinstance(arr, np.ndarray) and arr.dtype == np.object and arr.shape == (3,)
338+
assert isinstance(arr, np.ndarray) and arr.dtype == object and arr.shape == (3,)
339339
np.testing.assert_equal(arr[0], dummy_array)
340340
np.testing.assert_equal(arr[2], dummy_array)
341341
assert np.isnan(arr[1]) # a single np.nan value - np.all not needed

tests/test_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ def _generate_examples(self):
837837
"builder_class, kwargs",
838838
[
839839
(DummyBuilderWithVersion, {}),
840-
(DummyBuilderWithBuilderConfigs, {"name": "custom"}),
841-
(DummyBuilderWithCustomBuilderConfigs, {"name": "20220501.en"}),
840+
(DummyBuilderWithBuilderConfigs, {"config_name": "custom"}),
841+
(DummyBuilderWithCustomBuilderConfigs, {"config_name": "20220501.en"}),
842842
(DummyBuilderWithCustomBuilderConfigs, {"date": "20220501", "language": "ca"}),
843843
],
844844
)

0 commit comments

Comments
 (0)