Skip to content

Commit

Permalink
Avoid some FutureWarnings and DeprecationWarnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosasko committed Jun 14, 2022
1 parent 3dbe753 commit 6eab0e4
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/datasets/arrow_dataset.py
Expand Up @@ -280,7 +280,7 @@ def _get_output_signature(
else:
np_arrays.append(np.array(array))

if np.issubdtype(np_arrays[0].dtype, np.integer) or np_arrays[0].dtype == np.bool:
if np.issubdtype(np_arrays[0].dtype, np.integer) or np_arrays[0].dtype == bool:
tf_dtype = tf.int64
np_dtype = np.int64
elif np.issubdtype(np_arrays[0].dtype, np.number):
Expand Down Expand Up @@ -3663,7 +3663,7 @@ def _feature(values: Union[float, int, str, np.ndarray]) -> "tf.train.Feature":
return _float_feature([values.item()])
elif np.issubdtype(values.dtype, np.integer):
return _int64_feature([values.item()])
elif np.issubdtype(values.dtype, np.str):
elif np.issubdtype(values.dtype, str):
return _bytes_feature([values.item().encode()])
else:
raise ValueError(f"values={values} has dtype {values.dtype}, which cannot be serialized")
Expand Down
2 changes: 1 addition & 1 deletion src/datasets/features/features.py
Expand Up @@ -810,7 +810,7 @@ def __getitem__(self, item: Union[int, slice, np.ndarray]) -> Union[np.ndarray,
def take(
self, indices: Sequence_[int], allow_fill: bool = False, fill_value: bool = None
) -> "PandasArrayExtensionArray":
indices: np.ndarray = np.asarray(indices, dtype=np.int)
indices: np.ndarray = np.asarray(indices, dtype=int)
if allow_fill:
fill_value = (
self.dtype.na_value if fill_value is None else np.asarray(fill_value, dtype=self.dtype.value_type)
Expand Down
4 changes: 2 additions & 2 deletions src/datasets/formatting/formatting.py
Expand Up @@ -194,11 +194,11 @@ def _arrow_array_to_numpy(self, pa_array: pa.Array) -> np.ndarray:
array: List = pa_array.to_numpy(zero_copy_only=zero_copy_only).tolist()
if len(array) > 0:
if any(
(isinstance(x, np.ndarray) and (x.dtype == np.object or x.shape != array[0].shape))
(isinstance(x, np.ndarray) and (x.dtype == object or x.shape != array[0].shape))
or (isinstance(x, float) and np.isnan(x))
for x in array
):
return np.array(array, copy=False, **{**self.np_array_kwargs, "dtype": np.object})
return np.array(array, copy=False, **{**self.np_array_kwargs, "dtype": object})
return np.array(array, copy=False, **self.np_array_kwargs)


Expand Down
2 changes: 1 addition & 1 deletion src/datasets/formatting/jax_formatter.py
Expand Up @@ -54,7 +54,7 @@ def _recursive_tensorize(self, data_struct: dict):
# support for nested types like struct of list of struct
if isinstance(data_struct, (list, np.ndarray)):
data_struct = np.array(data_struct, copy=False)
if data_struct.dtype == np.object: # jax arrays cannot be instantied from an array of objects
if data_struct.dtype == object: # jax arrays cannot be instantied from an array of objects
return [self.recursive_tensorize(substruct) for substruct in data_struct]
return self._tensorize(data_struct)

Expand Down
4 changes: 1 addition & 3 deletions src/datasets/formatting/tf_formatter.py
Expand Up @@ -65,9 +65,7 @@ def _tensorize(self, value):
def _recursive_tensorize(self, data_struct: dict):
# support for nested types like struct of list of struct
if isinstance(data_struct, (list, np.ndarray)):
if (
data_struct.dtype == np.object
): # tensorflow tensors can sometimes be instantied from an array of objects
if data_struct.dtype == object: # tensorflow tensors can sometimes be instantied from an array of objects
try:
return self._tensorize(data_struct)
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion src/datasets/formatting/torch_formatter.py
Expand Up @@ -46,7 +46,7 @@ def _recursive_tensorize(self, data_struct: dict):
# support for nested types like struct of list of struct
if isinstance(data_struct, (list, np.ndarray)):
data_struct = np.array(data_struct, copy=False)
if data_struct.dtype == np.object: # pytorch tensors cannot be instantied from an array of objects
if data_struct.dtype == object: # pytorch tensors cannot be instantied from an array of objects
return [self.recursive_tensorize(substruct) for substruct in data_struct]
return self._tensorize(data_struct)

Expand Down
2 changes: 1 addition & 1 deletion src/datasets/utils/stratify.py
Expand Up @@ -48,7 +48,7 @@ def approximate_mode(class_counts, n_draws, rng):
need_to_add -= add_now
if need_to_add == 0:
break
return floored.astype(np.int)
return floored.astype(int)


def stratified_shuffle_split_generate_indices(y, n_train, n_test, rng, n_splits=10):
Expand Down
2 changes: 1 addition & 1 deletion tests/features/test_array_xd.py
Expand Up @@ -335,7 +335,7 @@ def test_array_xd_with_none():
dummy_array = np.array([[1, 2], [3, 4]], dtype="int32")
dataset = datasets.Dataset.from_dict({"foo": [dummy_array, None, dummy_array]}, features=features)
arr = NumpyArrowExtractor().extract_column(dataset._data)
assert isinstance(arr, np.ndarray) and arr.dtype == np.object and arr.shape == (3,)
assert isinstance(arr, np.ndarray) and arr.dtype == object and arr.shape == (3,)
np.testing.assert_equal(arr[0], dummy_array)
np.testing.assert_equal(arr[2], dummy_array)
assert np.isnan(arr[1]) # a single np.nan value - np.all not needed
Expand Down
4 changes: 2 additions & 2 deletions tests/test_builder.py
Expand Up @@ -837,8 +837,8 @@ def _generate_examples(self):
"builder_class, kwargs",
[
(DummyBuilderWithVersion, {}),
(DummyBuilderWithBuilderConfigs, {"name": "custom"}),
(DummyBuilderWithCustomBuilderConfigs, {"name": "20220501.en"}),
(DummyBuilderWithBuilderConfigs, {"config_name": "custom"}),
(DummyBuilderWithCustomBuilderConfigs, {"config_name": "20220501.en"}),
(DummyBuilderWithCustomBuilderConfigs, {"date": "20220501", "language": "ca"}),
],
)
Expand Down

1 comment on commit 6eab0e4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show benchmarks

PyArrow==6.0.0

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.011067 / 0.011353 (-0.000286) 0.005121 / 0.011008 (-0.005887) 0.038395 / 0.038508 (-0.000113) 0.041541 / 0.023109 (0.018432) 0.422908 / 0.275898 (0.147009) 0.449837 / 0.323480 (0.126357) 0.007767 / 0.007986 (-0.000218) 0.004889 / 0.004328 (0.000561) 0.008950 / 0.004250 (0.004700) 0.051456 / 0.037052 (0.014403) 0.407789 / 0.258489 (0.149300) 0.449566 / 0.293841 (0.155725) 0.059034 / 0.128546 (-0.069512) 0.015197 / 0.075646 (-0.060449) 0.339607 / 0.419271 (-0.079665) 0.064222 / 0.043533 (0.020689) 0.415720 / 0.255139 (0.160581) 0.466604 / 0.283200 (0.183404) 0.115174 / 0.141683 (-0.026509) 1.787245 / 1.452155 (0.335090) 1.875813 / 1.492716 (0.383096)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.231440 / 0.018006 (0.213434) 0.536432 / 0.000490 (0.535942) 0.024018 / 0.000200 (0.023818) 0.000706 / 0.000054 (0.000652)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.028822 / 0.037411 (-0.008589) 0.135426 / 0.014526 (0.120900) 0.140441 / 0.176557 (-0.036116) 0.184593 / 0.737135 (-0.552542) 0.141568 / 0.296338 (-0.154770)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.605603 / 0.215209 (0.390393) 6.001822 / 2.077655 (3.924167) 2.465246 / 1.504120 (0.961126) 2.213126 / 1.541195 (0.671931) 2.197845 / 1.468490 (0.729355) 0.735488 / 4.584777 (-3.849289) 5.529679 / 3.745712 (1.783967) 1.502740 / 5.269862 (-3.767121) 1.486219 / 4.565676 (-3.079458) 0.082504 / 0.424275 (-0.341771) 0.013203 / 0.007607 (0.005596) 0.770835 / 0.226044 (0.544790) 7.767178 / 2.268929 (5.498250) 3.191306 / 55.444624 (-52.253318) 2.630203 / 6.876477 (-4.246273) 2.760795 / 2.142072 (0.618723) 0.905538 / 4.805227 (-3.899689) 0.182215 / 6.500664 (-6.318449) 0.080209 / 0.075469 (0.004740)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.966272 / 1.841788 (0.124485) 17.302119 / 8.074308 (9.227811) 41.054461 / 10.191392 (30.863069) 1.174997 / 0.680424 (0.494573) 0.742324 / 0.534201 (0.208123) 0.492501 / 0.579283 (-0.086782) 0.592623 / 0.434364 (0.158259) 0.358653 / 0.540337 (-0.181685) 0.393893 / 1.386936 (-0.993043)
PyArrow==latest
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.010515 / 0.011353 (-0.000838) 0.005076 / 0.011008 (-0.005933) 0.036992 / 0.038508 (-0.001516) 0.034318 / 0.023109 (0.011209) 0.409642 / 0.275898 (0.133744) 0.425180 / 0.323480 (0.101700) 0.004862 / 0.007986 (-0.003123) 0.004255 / 0.004328 (-0.000074) 0.006938 / 0.004250 (0.002688) 0.039447 / 0.037052 (0.002395) 0.396288 / 0.258489 (0.137799) 0.445090 / 0.293841 (0.151249) 0.046307 / 0.128546 (-0.082239) 0.015163 / 0.075646 (-0.060484) 0.315812 / 0.419271 (-0.103459) 0.064216 / 0.043533 (0.020683) 0.393150 / 0.255139 (0.138011) 0.427625 / 0.283200 (0.144426) 0.119725 / 0.141683 (-0.021958) 1.741552 / 1.452155 (0.289397) 1.773424 / 1.492716 (0.280707)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.287102 / 0.018006 (0.269095) 0.590078 / 0.000490 (0.589588) 0.066884 / 0.000200 (0.066684) 0.000598 / 0.000054 (0.000544)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.029836 / 0.037411 (-0.007575) 0.138606 / 0.014526 (0.124080) 0.138653 / 0.176557 (-0.037904) 0.203122 / 0.737135 (-0.534014) 0.139080 / 0.296338 (-0.157258)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.611462 / 0.215209 (0.396253) 6.032696 / 2.077655 (3.955041) 2.562656 / 1.504120 (1.058536) 2.301881 / 1.541195 (0.760686) 2.321476 / 1.468490 (0.852986) 0.707244 / 4.584777 (-3.877533) 5.495904 / 3.745712 (1.750192) 1.560831 / 5.269862 (-3.709030) 1.526627 / 4.565676 (-3.039049) 0.082338 / 0.424275 (-0.341937) 0.013601 / 0.007607 (0.005994) 0.738546 / 0.226044 (0.512502) 7.372311 / 2.268929 (5.103382) 3.244123 / 55.444624 (-52.200501) 2.723955 / 6.876477 (-4.152521) 2.829642 / 2.142072 (0.687569) 0.883451 / 4.805227 (-3.921776) 0.185630 / 6.500664 (-6.315034) 0.081919 / 0.075469 (0.006450)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.864562 / 1.841788 (0.022774) 16.374539 / 8.074308 (8.300231) 40.588652 / 10.191392 (30.397260) 1.094018 / 0.680424 (0.413594) 0.681631 / 0.534201 (0.147430) 0.471105 / 0.579283 (-0.108178) 0.608554 / 0.434364 (0.174190) 0.343113 / 0.540337 (-0.197224) 0.360185 / 1.386936 (-1.026751)

CML watermark

Please sign in to comment.