





import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry





class UpperCAmelCase_							(   _SCREAMING_SNAKE_CASE   ):
  __lowerCAmelCase      :	Optional[Any]  	=      """mock"""


  def __init__(       self   ,*__snake_case   ,__snake_case   ,**__snake_case   ):



       """simple docstring"""





       super().__init__()
       A_					      =					LocalFileSystem(*__snake_case   ,**__snake_case   )
       A_					      =					Path(__snake_case   ).resolve().as_posix() + '''/'''


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.mkdir(__snake_case   ,*__snake_case   ,**__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.makedirs(__snake_case   ,*__snake_case   ,**__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.rmdir(__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,__snake_case=True   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       A_					      =					self._fs.ls(__snake_case   ,detail=__snake_case   ,*__snake_case   ,**__snake_case   )
       if detail:
            return [{**info, "name": info["name"][len(self.local_root_dir   ) :]} for info in out]
       else:
            return [name[len(self.local_root_dir   ) :] for name in out]


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       A_					      =					dict(self._fs.info(__snake_case   ,*__snake_case   ,**__snake_case   )   )
       A_					      =					out['''name'''][len(self.local_root_dir   ) :]
       return out


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.cp_file(__snake_case   ,__snake_case   ,*__snake_case   ,**__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.rm_file(__snake_case   ,*__snake_case   ,**__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.rm(__snake_case   ,*__snake_case   ,**__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs._open(__snake_case   ,*__snake_case   ,**__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.created(__snake_case   )


  def 	__UpperCAmelCase    (       self   ,__snake_case   ):



       """simple docstring"""





       A_					      =					posixpath.join(self.local_root_dir   ,self._strip_protocol(__snake_case   )   )
       return self._fs.modified(__snake_case   )




  @classmethod
  def 	__UpperCAmelCase    (       cls   ,__snake_case   ):



       """simple docstring"""





       A_					      =					stringify_path(__snake_case   )
       if path.startswith('''mock://'''   ):
            A_					      =					path[7:]
       return path





class UpperCAmelCase_							(   _SCREAMING_SNAKE_CASE   ):
  __lowerCAmelCase      :	str  	=      """tmp"""
  __lowerCAmelCase      :	Any  	=      None


  def __init__(       self   ,*__snake_case   ,**__snake_case   ):



       """simple docstring"""





       assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
       super().__init__(*__snake_case   ,**__snake_case   ,local_root_dir=self.tmp_dir   ,auto_mkdir=__snake_case   )




  @classmethod
  def 	__UpperCAmelCase    (       cls   ,__snake_case   ):



       """simple docstring"""





       A_					      =					stringify_path(__snake_case   )
       if path.startswith('''tmp://'''   ):
            A_					      =					path[6:]
       return path




@pytest.fixture
def     UpperCAmelCase_						(						)  ->							Dict:
     '''simple docstring'''


     A_					      =					MockFileSystem
     A_					      =					TmpDirFileSystem
     yield
     del _fsspec_registry["mock"]
     del _fsspec_registry["tmp"]

@pytest.fixture
def     UpperCAmelCase_						(						_UpperCAmelCase       :Optional[Any]     ,	_UpperCAmelCase       :Dict							)  ->							Dict:
     '''simple docstring'''


     A_					      =					tmp_path_factory.mktemp('''mockfs'''							)
     return MockFileSystem(local_root_dir=_UpperCAmelCase     ,	auto_mkdir=_UpperCAmelCase							)


@pytest.fixture
def     UpperCAmelCase_						(						_UpperCAmelCase       :List[str]     ,	_UpperCAmelCase       :Dict							)  ->							List[Any]:
     '''simple docstring'''


     A_					      =					tmp_path_factory.mktemp('''tmpfs'''							)
     with patch.object(_UpperCAmelCase     ,	'''tmp_dir'''     ,	_UpperCAmelCase							):
          yield TmpDirFileSystem()










from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load iris file
a__			:    List[str]			      =		load_iris()
iris.keys()


print(f'''Target names: \n {iris.target_names} ''')
print(f'''\n Features: \n {iris.feature_names}''')

# Train set e Test set
a__      ,							a__      ,							a__      ,							a__			:    Any			      =		train_test_split(
    iris['data'], iris['target'], random_state=4
)

# KNN

a__			:    List[Any]			      =		KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)

# new array to test
a__			:    Optional[Any]			      =		[[1, 2, 1, 4], [2, 3, 4, 5]]

a__			:    Union[str, Any]			      =		knn.predict(X_new)

print(
    f'''\nNew array: \n {X_new}\n\nTarget Names Prediction: \n'''
    f''' {iris['target_names'][prediction]}'''
)



