Skip to content

Commit a325ae3

Browse files
authored
Remove conditions for Python < 3.9 (#7474)
* Remove code for Python < 3.9 * Make style Signed-off-by: cyy <[email protected]> --------- Signed-off-by: cyy <[email protected]>
1 parent 6a96bf3 commit a325ae3

File tree

3 files changed

+46
-52
lines changed

3 files changed

+46
-52
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
AUDIO_REQUIRE = [
142142
"soundfile>=0.12.1",
143143
"librosa",
144-
"soxr>=0.4.0; python_version>='3.9'", # Supports numpy-2
144+
"soxr>=0.4.0", # Supports numpy-2
145145
]
146146

147147
VISION_REQUIRE = [

src/datasets/formatting/formatting.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import numpy as np
2323
import pandas as pd
2424
import pyarrow as pa
25-
from packaging import version
2625

27-
from .. import config
2826
from ..features import Features
2927
from ..features.features import _ArrayXDExtensionType, _is_zero_copy_only, decode_nested_example, pandas_types_mapper
3028
from ..table import Table
@@ -304,49 +302,46 @@ def __repr__(self):
304302
self._format_all()
305303
return repr(self.data)
306304

307-
if config.PY_VERSION >= version.parse("3.9"):
308-
# merging with the union ("|") operator is supported in Python 3.9+
309-
310-
def __or__(self, other):
311-
if isinstance(other, LazyDict):
312-
inst = self.copy()
313-
other = other.copy()
314-
other._format_all()
315-
inst.keys_to_format -= other.data.keys()
316-
inst.data = inst.data | other.data
317-
return inst
318-
if isinstance(other, dict):
319-
inst = self.copy()
320-
inst.keys_to_format -= other.keys()
321-
inst.data = inst.data | other
322-
return inst
323-
return NotImplemented
324-
325-
def __ror__(self, other):
326-
if isinstance(other, LazyDict):
327-
inst = self.copy()
328-
other = other.copy()
329-
other._format_all()
330-
inst.keys_to_format -= other.data.keys()
331-
inst.data = other.data | inst.data
332-
return inst
333-
if isinstance(other, dict):
334-
inst = self.copy()
335-
inst.keys_to_format -= other.keys()
336-
inst.data = other | inst.data
337-
return inst
338-
return NotImplemented
339-
340-
def __ior__(self, other):
341-
if isinstance(other, LazyDict):
342-
other = other.copy()
343-
other._format_all()
344-
self.keys_to_format -= other.data.keys()
345-
self.data |= other.data
346-
else:
347-
self.keys_to_format -= other.keys()
348-
self.data |= other
349-
return self
305+
def __or__(self, other):
306+
if isinstance(other, LazyDict):
307+
inst = self.copy()
308+
other = other.copy()
309+
other._format_all()
310+
inst.keys_to_format -= other.data.keys()
311+
inst.data = inst.data | other.data
312+
return inst
313+
if isinstance(other, dict):
314+
inst = self.copy()
315+
inst.keys_to_format -= other.keys()
316+
inst.data = inst.data | other
317+
return inst
318+
return NotImplemented
319+
320+
def __ror__(self, other):
321+
if isinstance(other, LazyDict):
322+
inst = self.copy()
323+
other = other.copy()
324+
other._format_all()
325+
inst.keys_to_format -= other.data.keys()
326+
inst.data = other.data | inst.data
327+
return inst
328+
if isinstance(other, dict):
329+
inst = self.copy()
330+
inst.keys_to_format -= other.keys()
331+
inst.data = other | inst.data
332+
return inst
333+
return NotImplemented
334+
335+
def __ior__(self, other):
336+
if isinstance(other, LazyDict):
337+
other = other.copy()
338+
other._format_all()
339+
self.keys_to_format -= other.data.keys()
340+
self.data |= other.data
341+
else:
342+
self.keys_to_format -= other.keys()
343+
self.data |= other
344+
return self
350345

351346
def __copy__(self):
352347
# Identical to `UserDict.__copy__`

tests/test_arrow_dataset.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,12 +3175,11 @@ def test_tf_dataset_options(self, in_memory):
31753175
self.assertEqual(len(tf_dataset), 2) # One batch of 3 and one batch of 1
31763176
self.assertEqual(len(tf_dataset_with_drop), 1) # Incomplete batch of 1 is dropped
31773177
# Test that `NotImplementedError` is raised `batch_size` is None and `num_workers` is > 0
3178-
if sys.version_info >= (3, 8):
3179-
with self._create_dummy_dataset(in_memory, tmp_dir.name, multiple_columns=True) as dset:
3180-
with self.assertRaisesRegex(
3181-
NotImplementedError, "`batch_size` must be specified when using multiple workers"
3182-
):
3183-
dset.to_tf_dataset(columns="col_1", batch_size=None, num_workers=2)
3178+
with self._create_dummy_dataset(in_memory, tmp_dir.name, multiple_columns=True) as dset:
3179+
with self.assertRaisesRegex(
3180+
NotImplementedError, "`batch_size` must be specified when using multiple workers"
3181+
):
3182+
dset.to_tf_dataset(columns="col_1", batch_size=None, num_workers=2)
31843183
del tf_dataset # For correct cleanup
31853184
del tf_dataset_with_drop
31863185

0 commit comments

Comments
 (0)