



import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
	import jax.numpy as jnp

class  __snake_case      (   SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							def __get__(							self  ,  a_  ,  a_=None		):
											# See docs.python.org/3/howto/descriptor.html#properties
											if obj is None:
															return self
											if self.fget is None:
															raise AttributeError("""unreadable attribute"""		)
											a__				      =		"""__cached_""" + self.fget.__name__
											a__				      =		getattr(a_  ,  a_  ,  a_		)
											if cached is None:
															a__				      =		self.fget(a_		)
															setattr(a_  ,  a_  ,  a_		)
											return cached




def 			A_      (	__a     :				Any		):

				"""simple docstring"""
				a__				      =		val.lower()
				if val in {"y", "yes", "t", "true", "on", "1"}:
								return 1
				if val in {"n", "no", "f", "false", "off", "0"}:
								return 0
				raise ValueError(F'''invalid truth value {val!r}'''		)

def 			A_      (	__a     :				Optional[int]		):

				"""simple docstring"""
				if is_torch_fx_proxy(__a		):
								return True
				if is_torch_available():
								import torch

								if isinstance(__a ,		torch.Tensor		):
												return True
				if is_tf_available():
								import tensorflow as tf

								if isinstance(__a ,		tf.Tensor		):
												return True

				if is_flax_available():
								import jax.numpy as jnp
								from jax.core import Tracer

								if isinstance(__a ,		(jnp.ndarray, Tracer)		):
												return True

				return isinstance(__a ,		np.ndarray		)

def 			A_      (	__a     :				List[Any]		):

				"""simple docstring"""
				return isinstance(__a ,		np.ndarray		)

def 			A_      (	__a     :				int		):

				"""simple docstring"""
				return _is_numpy(__a		)

def 			A_      (	__a     :				str		):

				"""simple docstring"""
				import torch

				return isinstance(__a ,		torch.Tensor		)

def 			A_      (	__a     :				Dict		):

				"""simple docstring"""
				return False if not is_torch_available() else _is_torch(__a		)

def 			A_      (	__a     :				List[str]		):

				"""simple docstring"""
				import torch

				return isinstance(__a ,		torch.device		)

def 			A_      (	__a     :				List[str]		):

				"""simple docstring"""
				return False if not is_torch_available() else _is_torch_device(__a		)

def 			A_      (	__a     :				Union[str, Any]		):

				"""simple docstring"""
				import torch

				if isinstance(__a ,		__a		):
								if hasattr(__a ,		__a		):
												a__				      =		getattr(__a ,		__a		)
								else:
												return False
				return isinstance(__a ,		torch.dtype		)

def 			A_      (	__a     :				Union[str, Any]		):

				"""simple docstring"""
				return False if not is_torch_available() else _is_torch_dtype(__a		)

def 			A_      (	__a     :				Dict		):

				"""simple docstring"""
				import tensorflow as tf

				return isinstance(__a ,		tf.Tensor		)

def 			A_      (	__a     :				Optional[Any]		):

				"""simple docstring"""
				return False if not is_tf_available() else _is_tensorflow(__a		)

def 			A_      (	__a     :				Dict		):

				"""simple docstring"""
				import tensorflow as tf

				# the `is_symbolic_tensor` predicate is only available starting with TF 2.14
				if hasattr(__a ,		"""is_symbolic_tensor"""		):
								return tf.is_symbolic_tensor(__a		)
				return type(__a		) == tf.Tensor

def 			A_      (	__a     :				Optional[int]		):

				"""simple docstring"""
				return False if not is_tf_available() else _is_tf_symbolic_tensor(__a		)

def 			A_      (	__a     :				Tuple		):

				"""simple docstring"""
				import jax.numpy as jnp  # noqa: F811

				return isinstance(__a ,		jnp.ndarray		)

def 			A_      (	__a     :				List[str]		):

				"""simple docstring"""
				return False if not is_flax_available() else _is_jax(__a		)

def 			A_      (	__a     :				List[str]		):

				"""simple docstring"""
				if isinstance(__a ,		(dict, UserDict)		):
								return {k: to_py_obj(__a		) for k, v in obj.items()}
				elif isinstance(__a ,		(list, tuple)		):
								return [to_py_obj(__a		) for o in obj]
				elif is_tf_tensor(__a		):
								return obj.numpy().tolist()
				elif is_torch_tensor(__a		):
								return obj.detach().cpu().tolist()
				elif is_jax_tensor(__a		):
								return np.asarray(__a		).tolist()
				elif isinstance(__a ,		(np.ndarray, np.number)		):  # tolist also works on 0d np arrays
								return obj.tolist()
				else:
								return obj

def 			A_      (	__a     :				Tuple		):

				"""simple docstring"""
				if isinstance(__a ,		(dict, UserDict)		):
								return {k: to_numpy(__a		) for k, v in obj.items()}
				elif isinstance(__a ,		(list, tuple)		):
								return np.array(__a		)
				elif is_tf_tensor(__a		):
								return obj.numpy()
				elif is_torch_tensor(__a		):
								return obj.detach().cpu().numpy()
				elif is_jax_tensor(__a		):
								return np.asarray(__a		)
				else:
								return obj

class  __snake_case      (   SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							def _a      (							self		):
											a__				      =		fields(self		)

											# Safety and consistency checks
											if not len(a_		):
															raise ValueError(F'''{self.__class__.__name__} has no fields.'''		)
											if not all(field.default is None for field in class_fields[1:]		):
															raise ValueError(F'''{self.__class__.__name__} should not have more than one required field.'''		)

											a__				      =		getattr(self  ,  class_fields[0].name		)
											a__				      =		all(getattr(self  ,  field.name		) is None for field in class_fields[1:]		)

											if other_fields_are_none and not is_tensor(a_		):
															if isinstance(a_  ,  a_		):
																			a__				      =		first_field.items()
																			a__				      =		True
															else:
																			try:
																							a__				      =		iter(a_		)
																							a__				      =		True
																			except TypeError:
																							a__				      =		False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
															if first_field_iterator:
																			for idx, element in enumerate(a_		):
																							if (
																							    not isinstance(a_  ,  (list, tuple)		)
																							    or not len(a_		) == 2
																							    or not isinstance(element[0]  ,  a_		)
																							):
																											if idx == 0:
																															# If we do not have an iterator of key/values, set it as attribute
																															a__				      =		first_field
																											else:
																															# If we have a mixed iterator, raise an error
																															raise ValueError(
																															    F'''Cannot set key/value for {element}. It needs to be a tuple (key, value).'''		)
																											break
																							setattr(self  ,  element[0]  ,  element[1]		)
																							if element[1] is not None:
																											a__				      =		element[1]
															elif first_field is not None:
																			a__				      =		first_field
											else:
															for field in class_fields:
																			a__				      =		getattr(self  ,  field.name		)
																			if v is not None:
																							a__				      =		v


							def __delitem__(							self  ,  *a_  ,  **a_		):
											raise Exception(F'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''		)


							def _a      (							self  ,  *a_  ,  **a_		):
											raise Exception(F'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''		)


							def _a      (							self  ,  *a_  ,  **a_		):
											raise Exception(F'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''		)


							def _a      (							self  ,  *a_  ,  **a_		):
											raise Exception(F'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''		)


							def __getitem__(							self  ,  a_		):
											if isinstance(a_  ,  a_		):
															a__				      =		dict(self.items()		)
															return inner_dict[k]
											else:
															return self.to_tuple()[k]


							def __setattr__(							self  ,  a_  ,  a_		):
											if name in self.keys() and value is not None:
															# Don't call self.__setitem__ to avoid recursion errors
															super().__setitem__(a_  ,  a_		)
											super().__setattr__(a_  ,  a_		)


							def __setitem__(							self  ,  a_  ,  a_		):
											# Will raise a KeyException if needed
											super().__setitem__(a_  ,  a_		)
											# Don't call self.__setattr__ to avoid recursion errors
											super().__setattr__(a_  ,  a_		)







							def _a      (							self		):
											return tuple(self[k] for k in self.keys()		)




class  __snake_case      (   SCREAMING_SNAKE_CASE			,SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							@classmethod
							def _a      (							cls  ,  a_		):
											raise ValueError(
											    F'''{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()		)}'''		)




class  __snake_case      (   SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							UpperCamelCase__				:      Any         =					"""longest"""
							UpperCamelCase__				:      List[Any]         =					"""max_length"""
							UpperCamelCase__				:      str         =					"""do_not_pad"""




class  __snake_case      (   SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							UpperCamelCase__				:      Any         =					"""pt"""
							UpperCamelCase__				:      Any         =					"""tf"""
							UpperCamelCase__				:      Tuple         =					"""np"""
							UpperCamelCase__				:      Any         =					"""jax"""




class  __snake_case      :







							'''simple docstring'''






							def __init__(							self  ,  a_		):
											a__				      =		context_managers
											a__				      =		ExitStack()


							def __enter__(							self		):
											for context_manager in self.context_managers:
															self.stack.enter_context(a_		)







							def __exit__(							self  ,  *a_  ,  **a_		):
											self.stack.__exit__(*a_  ,  **a_		)




def 			A_      (	__a     :				Optional[Any]		):

				"""simple docstring"""
				a__				      =		infer_framework(__a		)
				if framework == "tf":
								a__				      =		inspect.signature(model_class.call		)  # TensorFlow models
				elif framework == "pt":
								a__				      =		inspect.signature(model_class.forward		)  # PyTorch models
				else:
								a__				      =		inspect.signature(model_class.__call__		)  # Flax models

				for p in signature.parameters:
								if p == "return_loss" and signature.parameters[p].default is True:
												return True

				return False

def 			A_      (	__a     :				List[Any]		):

				"""simple docstring"""
				a__				      =		model_class.__name__
				a__				      =		infer_framework(__a		)
				if framework == "tf":
								a__				      =		inspect.signature(model_class.call		)  # TensorFlow models
				elif framework == "pt":
								a__				      =		inspect.signature(model_class.forward		)  # PyTorch models
				else:
								a__				      =		inspect.signature(model_class.__call__		)  # Flax models

				if "QuestionAnswering" in model_name:
								return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
				else:
								return [p for p in signature.parameters if "label" in p]

def 			A_      (	__a     :				MutableMapping ,		__a     :				str = "" ,		__a     :				str = "."		):

				"""simple docstring"""

				def _flatten_dict(__a     :				str ,		__a     :				str="" ,		__a     :				Union[str, Any]="."		):
								for k, v in d.items():
												a__				      =		str(__a		) + delimiter + str(__a		) if parent_key else k
												if v and isinstance(__a ,		__a		):
																yield from flatten_dict(__a ,		__a ,		delimiter=__a		).items()
												else:
																yield key, v

				return dict(_flatten_dict(__a ,		__a ,		__a		)		)

@contextmanager
def 			A_      (	__a     :				Optional[Any] ,		__a     :				bool = False		):

				"""simple docstring"""
				if use_temp_dir:
								with tempfile.TemporaryDirectory() as tmp_dir:
												yield tmp_dir
				else:
								yield working_dir

def 			A_      (	__a     :				Any ,		__a     :				Dict=None		):

				"""simple docstring"""
				if is_numpy_array(__a		):
								return np.transpose(__a ,		axes=__a		)
				elif is_torch_tensor(__a		):
								return array.T if axes is None else array.permute(*__a		)
				elif is_tf_tensor(__a		):
								import tensorflow as tf

								return tf.transpose(__a ,		perm=__a		)
				elif is_jax_tensor(__a		):
								return jnp.transpose(__a ,		axes=__a		)
				else:
								raise ValueError(F'''Type not supported for transpose: {type(__a		)}.'''		)

def 			A_      (	__a     :				Dict ,		__a     :				Optional[Any]		):

				"""simple docstring"""
				if is_numpy_array(__a		):
								return np.reshape(__a ,		__a		)
				elif is_torch_tensor(__a		):
								return array.reshape(*__a		)
				elif is_tf_tensor(__a		):
								import tensorflow as tf

								return tf.reshape(__a ,		__a		)
				elif is_jax_tensor(__a		):
								return jnp.reshape(__a ,		__a		)
				else:
								raise ValueError(F'''Type not supported for reshape: {type(__a		)}.'''		)

def 			A_      (	__a     :				int ,		__a     :				Optional[int]=None		):

				"""simple docstring"""
				if is_numpy_array(__a		):
								return np.squeeze(__a ,		axis=__a		)
				elif is_torch_tensor(__a		):
								return array.squeeze() if axis is None else array.squeeze(dim=__a		)
				elif is_tf_tensor(__a		):
								import tensorflow as tf

								return tf.squeeze(__a ,		axis=__a		)
				elif is_jax_tensor(__a		):
								return jnp.squeeze(__a ,		axis=__a		)
				else:
								raise ValueError(F'''Type not supported for squeeze: {type(__a		)}.'''		)

def 			A_      (	__a     :				Union[str, Any] ,		__a     :				Any		):

				"""simple docstring"""
				if is_numpy_array(__a		):
								return np.expand_dims(__a ,		__a		)
				elif is_torch_tensor(__a		):
								return array.unsqueeze(dim=__a		)
				elif is_tf_tensor(__a		):
								import tensorflow as tf

								return tf.expand_dims(__a ,		axis=__a		)
				elif is_jax_tensor(__a		):
								return jnp.expand_dims(__a ,		axis=__a		)
				else:
								raise ValueError(F'''Type not supported for expand_dims: {type(__a		)}.'''		)

def 			A_      (	__a     :				Optional[int]		):

				"""simple docstring"""
				if is_numpy_array(__a		):
								return np.size(__a		)
				elif is_torch_tensor(__a		):
								return array.numel()
				elif is_tf_tensor(__a		):
								import tensorflow as tf

								return tf.size(__a		)
				elif is_jax_tensor(__a		):
								return array.size
				else:
								raise ValueError(F'''Type not supported for expand_dims: {type(__a		)}.'''		)

def 			A_      (	__a     :				Tuple ,		__a     :				str		):

				"""simple docstring"""
				for key, value in auto_map.items():
								if isinstance(__a ,		(tuple, list)		):
												a__				      =		[F'''{repo_id}--{v}''' if (v is not None and """--""" not in v) else v for v in value]
								elif value is not None and "--" not in value:
												a__				      =		F'''{repo_id}--{value}'''

				return auto_map




def 			A_      (	__a     :				Tuple		):

				"""simple docstring"""
				for base_class in inspect.getmro(__a		):
								a__				      =		base_class.__module__
								a__				      =		base_class.__name__
								if module.startswith("""tensorflow"""		) or module.startswith("""keras"""		) or name == "TFPreTrainedModel":
												return "tf"
								elif module.startswith("""torch"""		) or name == "PreTrainedModel":
												return "pt"
								elif module.startswith("""flax"""		) or module.startswith("""jax"""		) or name == "FlaxPreTrainedModel":
												return "flax"
				else:
								raise TypeError(F'''Could not infer framework from class {model_class}.'''		)






import io
import json

import fsspec
import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.json import JsonDatasetReader, JsonDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases

def 			A_      (	__a     :				List[str] ,		__a     :				Optional[int]		):

				"""simple docstring"""
				assert isinstance(__a ,		__a		)
				assert dataset.num_rows == 4
				assert dataset.num_columns == 3
				assert dataset.column_names == ["col_1", "col_2", "col_3"]
				for feature, expected_dtype in expected_features.items():
								assert dataset.features[feature].dtype == expected_dtype

@pytest.mark.parametrize("""keep_in_memory""" ,		[False, True]		)
def 			A_      (	__a     :				Tuple ,		__a     :				Dict ,		__a     :				List[str]		):

				"""simple docstring"""
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
								a__				      =		JsonDatasetReader(__a ,		cache_dir=__a ,		keep_in_memory=__a		).read()
				_check_json_dataset(__a ,		__a		)

@pytest.mark.parametrize(
    """features""" ,		[
        None,
        {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""},
        {"""col_1""": """string""", """col_2""": """string""", """col_3""": """string"""},
        {"""col_1""": """int32""", """col_2""": """int32""", """col_3""": """int32"""},
        {"""col_1""": """float32""", """col_2""": """float32""", """col_3""": """float32"""},
    ] ,		)
def 			A_      (	__a     :				int ,		__a     :				Dict ,		__a     :				List[Any]		):

				"""simple docstring"""
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				a__				      =		features.copy() if features else default_expected_features
				a__				      =		(
				    Features({feature: Value(__a		) for feature, dtype in features.items()}		) if features is not None else None
				)
				a__				      =		JsonDatasetReader(__a ,		features=__a ,		cache_dir=__a		).read()
				_check_json_dataset(__a ,		__a		)

@pytest.mark.parametrize(
    """features""" ,		[
        None,
        {"""col_3""": """float64""", """col_1""": """string""", """col_2""": """int64"""},
    ] ,		)
def 			A_      (	__a     :				Tuple ,		__a     :				Tuple ,		__a     :				Tuple		):

				"""simple docstring"""
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_3""": """float64""", """col_1""": """string""", """col_2""": """int64"""}
				a__				      =		features.copy() if features else default_expected_features
				a__				      =		(
				    Features({feature: Value(__a		) for feature, dtype in features.items()}		) if features is not None else None
				)
				a__				      =		JsonDatasetReader(__a ,		features=__a ,		cache_dir=__a		).read()
				assert isinstance(__a ,		__a		)
				assert dataset.num_rows == 2
				assert dataset.num_columns == 3
				assert dataset.column_names == ["col_3", "col_1", "col_2"]
				for feature, expected_dtype in expected_features.items():
								assert dataset.features[feature].dtype == expected_dtype

def 			A_      (	__a     :				int ,		__a     :				Optional[Any]		):

				"""simple docstring"""
				# jsonl_312_path features are {"col_3": "float64", "col_1": "string", "col_2": "int64"}
				a__				      =		{"""col_2""": """int64""", """col_3""": """float64""", """col_1""": """string"""}
				a__				      =		features.copy()
				a__				      =		(
				    Features({feature: Value(__a		) for feature, dtype in features.items()}		) if features is not None else None
				)
				a__				      =		tmp_path / """cache"""
				a__				      =		JsonDatasetReader(__a ,		features=__a ,		cache_dir=__a		).read()
				assert isinstance(__a ,		__a		)
				assert dataset.num_rows == 2
				assert dataset.num_columns == 3
				assert dataset.column_names == ["col_2", "col_3", "col_1"]
				for feature, expected_dtype in expected_features.items():
								assert dataset.features[feature].dtype == expected_dtype

@pytest.mark.parametrize("""split""" ,		[None, NamedSplit("""train"""		), """train""", """test"""]		)
def 			A_      (	__a     :				List[Any] ,		__a     :				int ,		__a     :				List[str]		):

				"""simple docstring"""
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				a__				      =		JsonDatasetReader(__a ,		cache_dir=__a ,		split=__a		).read()
				_check_json_dataset(__a ,		__a		)
				assert dataset.split == split if split else "train"

@pytest.mark.parametrize("""path_type""" ,		[str, list]		)
def 			A_      (	__a     :				Dict ,		__a     :				Tuple ,		__a     :				List[str]		):

				"""simple docstring"""
				if issubclass(__a ,		__a		):
								a__				      =		jsonl_path
				elif issubclass(__a ,		__a		):
								a__				      =		[jsonl_path]
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				a__				      =		JsonDatasetReader(__a ,		cache_dir=__a		).read()
				_check_json_dataset(__a ,		__a		)

def 			A_      (	__a     :				str ,		__a     :				List[Any] ,		__a     :				Dict=("train",)		):

				"""simple docstring"""
				assert isinstance(__a ,		__a		)
				for split in splits:
								a__				      =		dataset_dict[split]
								assert dataset.num_rows == 4
								assert dataset.num_columns == 3
								assert dataset.column_names == ["col_1", "col_2", "col_3"]
								for feature, expected_dtype in expected_features.items():
												assert dataset.features[feature].dtype == expected_dtype

@pytest.mark.parametrize("""keep_in_memory""" ,		[False, True]		)
def 			A_      (	__a     :				int ,		__a     :				int ,		__a     :				Dict		):

				"""simple docstring"""
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
								a__				      =		JsonDatasetReader({"""train""": jsonl_path} ,		cache_dir=__a ,		keep_in_memory=__a		).read()
				_check_json_datasetdict(__a ,		__a		)

@pytest.mark.parametrize(
    """features""" ,		[
        None,
        {"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""},
        {"""col_1""": """string""", """col_2""": """string""", """col_3""": """string"""},
        {"""col_1""": """int32""", """col_2""": """int32""", """col_3""": """int32"""},
        {"""col_1""": """float32""", """col_2""": """float32""", """col_3""": """float32"""},
    ] ,		)
def 			A_      (	__a     :				Tuple ,		__a     :				Dict ,		__a     :				Optional[Any]		):

				"""simple docstring"""
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				a__				      =		features.copy() if features else default_expected_features
				a__				      =		(
				    Features({feature: Value(__a		) for feature, dtype in features.items()}		) if features is not None else None
				)
				a__				      =		JsonDatasetReader({"""train""": jsonl_path} ,		features=__a ,		cache_dir=__a		).read()
				_check_json_datasetdict(__a ,		__a		)

@pytest.mark.parametrize("""split""" ,		[None, NamedSplit("""train"""		), """train""", """test"""]		)
def 			A_      (	__a     :				Dict ,		__a     :				Any ,		__a     :				Tuple		):

				"""simple docstring"""
				if split:
								a__				      =		{split: jsonl_path}
				else:
								a__				      =		"""train"""
								a__				      =		{"""train""": jsonl_path, """test""": jsonl_path}
				a__				      =		tmp_path / """cache"""
				a__				      =		{"""col_1""": """string""", """col_2""": """int64""", """col_3""": """float64"""}
				a__				      =		JsonDatasetReader(__a ,		cache_dir=__a		).read()
				_check_json_datasetdict(__a ,		__a ,		splits=list(path.keys()		)		)
				assert all(dataset[split].split == split for split in path.keys()		)

def 			A_      (	__a     :				Any		):

				"""simple docstring"""
				return json.load(__a		)

def 			A_      (	__a     :				Tuple		):

				"""simple docstring"""
				return [json.loads(__a		) for line in buffer]




class  __snake_case      :







							'''simple docstring'''






							@pytest.mark.parametrize("""lines, load_json_function"""  ,  [(True, load_json_lines), (False, load_json)]		)
							def _a      (							self  ,  a_  ,  a_  ,  a_		):
											with io.BytesIO() as buffer:
															JsonDatasetWriter(a_  ,  a_  ,  lines=a_		).write()
															buffer.seek(0		)
															a__				      =		load_json_function(a_		)
											assert isinstance(a_  ,  a_		)
											assert isinstance(exported_content[0]  ,  a_		)
											assert len(a_		) == 10


							@pytest.mark.parametrize(
							    """orient, container, keys, len_at"""  ,  [
							        ("""records""", list, {"""tokens""", """labels""", """answers""", """id"""}, None),
							        ("""split""", dict, {"""columns""", """data"""}, """data"""),
							        ("""index""", dict, set("""0123456789"""		), None),
							        ("""columns""", dict, {"""tokens""", """labels""", """answers""", """id"""}, """tokens"""),
							        ("""values""", list, None, None),
							        ("""table""", dict, {"""schema""", """data"""}, """data"""),
							    ]  ,  )
							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											with io.BytesIO() as buffer:
															JsonDatasetWriter(a_  ,  a_  ,  lines=a_  ,  orient=a_		).write()
															buffer.seek(0		)
															a__				      =		load_json(a_		)
											assert isinstance(a_  ,  a_		)
											if keys:
															if container is dict:
																			assert exported_content.keys() == keys
															else:
																			assert exported_content[0].keys() == keys
											else:
															assert not hasattr(a_  ,  """keys"""		) and not hasattr(exported_content[0]  ,  """keys"""		)
											if len_at:
															assert len(exported_content[len_at]		) == 10
											else:
															assert len(a_		) == 10


							@pytest.mark.parametrize("""lines, load_json_function"""  ,  [(True, load_json_lines), (False, load_json)]		)
							def _a      (							self  ,  a_  ,  a_  ,  a_		):
											with io.BytesIO() as buffer:
															JsonDatasetWriter(a_  ,  a_  ,  lines=a_  ,  num_proc=2		).write()
															buffer.seek(0		)
															a__				      =		load_json_function(a_		)
											assert isinstance(a_  ,  a_		)
											assert isinstance(exported_content[0]  ,  a_		)
											assert len(a_		) == 10


							@pytest.mark.parametrize(
							    """orient, container, keys, len_at"""  ,  [
							        ("""records""", list, {"""tokens""", """labels""", """answers""", """id"""}, None),
							        ("""split""", dict, {"""columns""", """data"""}, """data"""),
							        ("""index""", dict, set("""0123456789"""		), None),
							        ("""columns""", dict, {"""tokens""", """labels""", """answers""", """id"""}, """tokens"""),
							        ("""values""", list, None, None),
							        ("""table""", dict, {"""schema""", """data"""}, """data"""),
							    ]  ,  )
							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											with io.BytesIO() as buffer:
															JsonDatasetWriter(a_  ,  a_  ,  lines=a_  ,  orient=a_  ,  num_proc=2		).write()
															buffer.seek(0		)
															a__				      =		load_json(a_		)
											assert isinstance(a_  ,  a_		)
											if keys:
															if container is dict:
																			assert exported_content.keys() == keys
															else:
																			assert exported_content[0].keys() == keys
											else:
															assert not hasattr(a_  ,  """keys"""		) and not hasattr(exported_content[0]  ,  """keys"""		)
											if len_at:
															assert len(exported_content[len_at]		) == 10
											else:
															assert len(a_		) == 10


							def _a      (							self  ,  a_		):
											with pytest.raises(a_		):
															with io.BytesIO() as buffer:
																			JsonDatasetWriter(a_  ,  a_  ,  num_proc=0		)







							@pytest.mark.parametrize("""compression, extension"""  ,  [("""gzip""", """gz"""), ("""bz2""", """bz2"""), ("""xz""", """xz""")]		)
							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		tmp_path_factory.mktemp("""data"""		) / F'''test.json.{extension}'''
											a__				      =		str(shared_datadir / F'''test_file.json.{extension}'''		)
											JsonDatasetWriter(a_  ,  a_  ,  compression=a_		).write()

											with fsspec.open(a_  ,  """rb"""  ,  compression="""infer"""		) as f:
															a__				      =		f.read()
											with fsspec.open(a_  ,  """rb"""  ,  compression="""infer"""		) as f:
															a__				      =		f.read()
											assert exported_content == original_content

