152
152
Categorical ,
153
153
ExtensionArray ,
154
154
)
155
- from pandas .core .arrays .datetimes import (
156
- tz_to_dtype ,
157
- validate_tz_from_dtype ,
158
- )
159
155
from pandas .core .arrays .string_ import StringArray
160
156
from pandas .core .base import (
161
157
IndexOpsMixin ,
@@ -241,11 +237,6 @@ def join(
241
237
return cast (F , join )
242
238
243
239
244
- def disallow_kwargs (kwargs : dict [str , Any ]) -> None :
245
- if kwargs :
246
- raise TypeError (f"Unexpected keyword arguments { repr (set (kwargs ))} " )
247
-
248
-
249
240
def _new_Index (cls , d ):
250
241
"""
251
242
This is called upon unpickling, rather than the default which doesn't
@@ -437,29 +428,15 @@ def __new__(
437
428
copy : bool = False ,
438
429
name = None ,
439
430
tupleize_cols : bool = True ,
440
- ** kwargs ,
441
431
) -> Index :
442
432
443
- if kwargs :
444
- warnings .warn (
445
- "Passing keywords other than 'data', 'dtype', 'copy', 'name', "
446
- "'tupleize_cols' is deprecated and will raise TypeError in a "
447
- "future version. Use the specific Index subclass directly instead." ,
448
- FutureWarning ,
449
- stacklevel = find_stack_level (),
450
- )
451
-
452
433
from pandas .core .arrays import PandasArray
453
434
from pandas .core .indexes .range import RangeIndex
454
435
455
436
name = maybe_extract_name (name , data , cls )
456
437
457
438
if dtype is not None :
458
439
dtype = pandas_dtype (dtype )
459
- if "tz" in kwargs :
460
- tz = kwargs .pop ("tz" )
461
- validate_tz_from_dtype (dtype , tz )
462
- dtype = tz_to_dtype (tz )
463
440
464
441
if type (data ) is PandasArray :
465
442
# ensure users don't accidentally put a PandasArray in an index,
@@ -481,26 +458,24 @@ def __new__(
481
458
# non-EA dtype indexes have special casting logic, so we punt here
482
459
klass = cls ._dtype_to_subclass (dtype )
483
460
if klass is not Index :
484
- return klass (data , dtype = dtype , copy = copy , name = name , ** kwargs )
461
+ return klass (data , dtype = dtype , copy = copy , name = name )
485
462
486
463
ea_cls = dtype .construct_array_type ()
487
464
data = ea_cls ._from_sequence (data , dtype = dtype , copy = copy )
488
- disallow_kwargs (kwargs )
489
465
return Index ._simple_new (data , name = name )
490
466
491
467
elif is_ea_or_datetimelike_dtype (data_dtype ):
492
468
data_dtype = cast (DtypeObj , data_dtype )
493
469
klass = cls ._dtype_to_subclass (data_dtype )
494
470
if klass is not Index :
495
- result = klass (data , copy = copy , name = name , ** kwargs )
471
+ result = klass (data , copy = copy , name = name )
496
472
if dtype is not None :
497
473
return result .astype (dtype , copy = False )
498
474
return result
499
475
elif dtype is not None :
500
476
# GH#45206
501
477
data = data .astype (dtype , copy = False )
502
478
503
- disallow_kwargs (kwargs )
504
479
data = extract_array (data , extract_numpy = True )
505
480
return Index ._simple_new (data , name = name )
506
481
@@ -542,18 +517,14 @@ def __new__(
542
517
)
543
518
dtype = arr .dtype
544
519
545
- if kwargs :
546
- return cls (arr , dtype , copy = copy , name = name , ** kwargs )
547
-
548
520
klass = cls ._dtype_to_subclass (arr .dtype )
549
521
arr = klass ._ensure_array (arr , dtype , copy )
550
- disallow_kwargs (kwargs )
551
522
return klass ._simple_new (arr , name )
552
523
553
524
elif is_scalar (data ):
554
525
raise cls ._raise_scalar_data_error (data )
555
526
elif hasattr (data , "__array__" ):
556
- return Index (np .asarray (data ), dtype = dtype , copy = copy , name = name , ** kwargs )
527
+ return Index (np .asarray (data ), dtype = dtype , copy = copy , name = name )
557
528
else :
558
529
559
530
if tupleize_cols and is_list_like (data ):
@@ -566,9 +537,7 @@ def __new__(
566
537
# 10697
567
538
from pandas .core .indexes .multi import MultiIndex
568
539
569
- return MultiIndex .from_tuples (
570
- data , names = name or kwargs .get ("names" )
571
- )
540
+ return MultiIndex .from_tuples (data , names = name )
572
541
# other iterable of some kind
573
542
574
543
subarr = com .asarray_tuplesafe (data , dtype = _dtype_obj )
@@ -578,7 +547,7 @@ def __new__(
578
547
subarr , cast_numeric_deprecated = False
579
548
)
580
549
dtype = subarr .dtype
581
- return Index (subarr , dtype = dtype , copy = copy , name = name , ** kwargs )
550
+ return Index (subarr , dtype = dtype , copy = copy , name = name )
582
551
583
552
@classmethod
584
553
def _ensure_array (cls , data , dtype , copy : bool ):
@@ -7081,19 +7050,6 @@ def shape(self) -> Shape:
7081
7050
# See GH#27775, GH#27384 for history/reasoning in how this is defined.
7082
7051
return (len (self ),)
7083
7052
7084
- @final
7085
- def _deprecated_arg (self , value , name : str_t , methodname : str_t ) -> None :
7086
- """
7087
- Issue a FutureWarning if the arg/kwarg is not no_default.
7088
- """
7089
- if value is not no_default :
7090
- warnings .warn (
7091
- f"'{ name } ' argument in { methodname } is deprecated "
7092
- "and will be removed in a future version. Do not pass it." ,
7093
- FutureWarning ,
7094
- stacklevel = find_stack_level (),
7095
- )
7096
-
7097
7053
7098
7054
def ensure_index_from_sequences (sequences , names = None ) -> Index :
7099
7055
"""
@@ -7246,14 +7202,6 @@ def maybe_extract_name(name, obj, cls) -> Hashable:
7246
7202
return name
7247
7203
7248
7204
7249
- _cast_depr_msg = (
7250
- "In a future version, passing an object-dtype arraylike to pd.Index will "
7251
- "not infer numeric values to numeric dtype (matching the Series behavior). "
7252
- "To retain the old behavior, explicitly pass the desired dtype or use the "
7253
- "desired Index subclass"
7254
- )
7255
-
7256
-
7257
7205
def _maybe_cast_data_without_dtype (
7258
7206
subarr : np .ndarray , cast_numeric_deprecated : bool = True
7259
7207
) -> ArrayLike :
0 commit comments