Index#

class Index#

Immutable sequence used for indexing and alignment.

Example#

import pandasCore as pd

# Create Index
idx = pd.Index([1, 2, 3], name='my_index')
print(len(idx))  # 3

Attributes#

Attribute

Description

Example

T

Return the transpose (returns copy for 1D Index)

dtype

Return the dtype object of the underlying data

View

empty

Indicator whether Index is empty

View

has_duplicates

Return True if Index has duplicate values

hasnans

Return True if Index has NaN values

inferred_type

Return string describing the type of the Index

is_monotonic_decreasing

Return if the index is monotonic decreasing

View

is_monotonic_increasing

Return if the index is monotonic increasing

View

is_unique

Return if the index has unique values

View

name

Return the name of the Index

View

nbytes

Return the number of bytes in the underlying data

ndim

Number of dimensions (always 1 for Index)

View

nlevels

Number of levels (always 1 for non-MultiIndex)

View

shape

Return a tuple of the shape of the underlying data

View

size

Return the number of elements in the Index

View

str

Vectorized string functions for Index.

View

values

Return an array representing the data in the Index

Construction#

Method

Description

Example

__init__() (data: object = None, dtype: object = None, copy: bool = False, name: object = None, tupleize_cols: bool = True)

Immutable sequence used for indexing and alignment.

View

Indexing / Selection#

Method

Description

Example

__getitem__() (arg0: typing.SupportsInt)

Get element by position

take() (indices: collections.abc.Sequence[typing.SupportsInt], axis: typing.SupportsInt = 0, allow_fill: bool = True, fill_value: object = None, **kwargs)

Return a new Index of the values selected by the indices.

View

where() (cond: object, other: object = None)

Replace values where the condition is False.

Data Manipulation#

Method

Description

Example

drop() (labels: collections.abc.Sequence[typing.SupportsInt], errors: str = 'raise')

Make new Index with passed list of labels deleted.

View

droplevel() (level: object = 0)

Return Index with requested level removed.

insert() (loc: typing.SupportsInt, item: typing.SupportsInt)

Make new Index inserting new item at location.

View

reindex() (target: pandasCore.Index, method: object = None, level: object = None, limit: object = None, tolerance: object = None)

Create index with target’s values.

View

rename() (name: str | None, *, inplace: bool = False)

Alter Index name.

View

set_names() (names: str | None, *, level: object = None, inplace: bool = False)

Set Index name.

View

Missing Data#

Method

Description

Example

dropna() (how: str = 'any')

Return Index without NA/NaN values.

View

fillna() (value: object = None, downcast: object = None)

Fill NA/NaN values with the specified value.

View

isna() ()

Detect missing values.

View

isnull() ()

Detect missing values. Alias for isna.

View

notna() ()

Detect existing (non-missing) values.

View

notnull() ()

Detect existing (non-missing) values. Alias for notna.

View

Statistics#

Method

Description

Example

max() (axis: object = None, skipna: bool = True)

Return the maximum value of the Index.

View

min() (axis: object = None, skipna: bool = True)

Return the minimum value of the Index.

View

nunique() (dropna: bool = True)

Return number of unique elements in the Index.

View

value_counts() (normalize: bool = False, sort: bool = True, ascending: bool = False, bins: object = None, dropna: bool = True)

Return a dict containing counts of unique values.

View

Aggregation#

Method

Description

Example

groupby() (values: collections.abc.Sequence[typing.SupportsInt])

Group the index labels by a mapper.

View

map() (mapper: collections.abc.Callable, na_action: object = None)

Map values using input correspondence.

View

Comparison#

Method

Description

Example

__eq__() (arg0: object)

__ge__() (arg0: typing.SupportsInt)

__gt__() (arg0: typing.SupportsInt)

__le__() (arg0: typing.SupportsInt)

__lt__() (arg0: typing.SupportsInt)

__ne__() (arg0: object)

equals() (other: pandasCore.Index)

Determine if two Index objects are equal.

Sorting#

Method

Description

Example

argsort() (*args, **kwargs)

Return the integer indices that would sort the Index.

View

searchsorted() (value: object, side: str = 'left', sorter: object = None)

Find indices where elements should be inserted to maintain order.

View

sort_values() (*, return_indexer: bool = False, ascending: bool = True, na_position: str = 'last', key: object = None)

Return a sorted copy of the Index.

View

Reshaping#

Method

Description

Example

to_frame() (index: bool = True, name: object = None)

Create a DataFrame with a column containing the Index.

View

transpose() (*args)

Return the transpose, which is by definition self.

View

Combining#

Method

Description

Example

append() (other: pandasCore.Index)

Append a collection of Index objects together.

join() (other: pandasCore.Index, *, how: str = 'left', level: object = None, return_indexers: bool = False, sort: bool = False)

Compute join between Index and other Index.

Time Series#

Method

Description

Example

asof() (label: typing.SupportsInt)

Return the label from the index, or, if not present, the previous one.

View

diff() (periods: typing.SupportsInt = 1)

Computes the difference between consecutive values.

View

shift() (periods: typing.SupportsInt = 1, freq: object = None)

Shift index by desired number of periods.

View

I/O#

Method

Description

Example

to_flat_index() ()

Identity method.

View

to_list() ()

Return a list of the Index values

View

to_numpy() (dtype: object = None, copy: bool = False, na_value: object = None, **kwargs)

Return a NumPy ndarray representing the values in this Index

to_series() (index: object = None, name: object = None)

Create a Series with both index and values equal to the index keys.

View

tolist() ()

Return a list of the Index values

View

Conversion#

Method

Description

Example

astype() (dtype: object, copy: bool = True)

Create an Index with values cast to specified dtype.

copy() (name: object = None, deep: bool = False)

Make a copy of this object.

View

infer_objects() (copy: bool = True)

Attempt to infer better dtypes for object columns.

View

view() (cls: object = None)

Return a view of the Index data.

View

Iteration#

Method

Description

Example

__contains__() (arg0: typing.SupportsInt)

Return True if key is in the Index

__iter__() ()

Iterate over the Index values

__len__() ()

Return the number of elements

Set Operations#

Method

Description

Example

difference() (other: pandasCore.Index, sort: object = None)

Return a new Index with elements of index not in other.

drop_duplicates() (*, keep: str = 'first')

Return Index with duplicate values removed.

View

duplicated() (keep: str = 'first')

Indicate duplicate index values.

View

intersection() (other: pandasCore.Index, sort: bool = False)

Form the intersection of two Index objects.

isin() (values: collections.abc.Sequence[typing.SupportsInt], level: object = None)

Return a boolean array indicating whether each element is in values.

View

symmetric_difference() (other: pandasCore.Index, result_name: object = None, sort: object = None)

Compute the symmetric difference of two Index objects.

union() (other: pandasCore.Index, sort: object = None)

Form the union of two Index objects.

unique() (level: object = None)

Return unique values in the Index.

View

Datetime Methods#

Method

Description

Example

round() (decimals: typing.SupportsInt = 0)

Round each value in the Index to the given number of decimals.

View

Other Methods#

Method

Description

Example

__hash__()

__repr__() ()

__str__() (self, /)

Return str(self).

all() (*args, **kwargs)

Return whether all elements are Truthy.

any() (*args, **kwargs)

Return whether any element is Truthy.

argmax() (axis: object = None, skipna: bool = True, *args, **kwargs)

Return int position of the largest value in the Index.

View

argmin() (axis: object = None, skipna: bool = True, *args, **kwargs)

Return int position of the smallest value in the Index.

View

asof_locs() (where: pandasCore.Index, mask: collections.abc.Sequence[bool] | None = None)

Return the locations for asof-lookup of labels.

View

delete() (loc: object)

Make new Index with element(s) at position(s) removed.

View

factorize() (sort: bool = False, use_na_sentinel: bool = True)

Encode the object as an enumerated type.

View

format() (name: bool = False, formatter: object = None, na_rep: str = 'NaN')

Render a string representation of the Index.

View

get_indexer() (target: pandasCore.Index, method: object = None, limit: object = None, tolerance: object = None)

Compute indexer and mask for new index given the current index.

View

get_indexer_for() (target: collections.abc.Sequence[typing.SupportsInt])

Guaranteed to return an indexer even when target contains non-uniqu…

View

get_indexer_non_unique() (target: pandasCore.Index)

Compute indexer and mask for new index given a non-unique current i…

View

get_level_values() (level: object)

Return an Index of values for requested level.

View

get_loc() (key: typing.SupportsInt)

Get integer location for requested label.

View

get_slice_bound() (label: typing.SupportsInt, side: str)

Calculate slice bound that corresponds to given label.

View

holds_integer() ()

Whether the type is an integer type.

View

identical() (other: pandasCore.Index)

Check if two Index objects are identical (values and metadata).

item() ()

Return the first element of the underlying data as a Python scalar.

View

memory_usage() (deep: bool = False)

Memory usage of the Index.

View

putmask() (mask: collections.abc.Sequence[bool], value: typing.SupportsInt)

Return a new Index with values put in locations specified by mask.

View

ravel() (order: object = 'C')

Return a flattened numpy array representing the values.

repeat() (repeats: object, axis: object = None)

Repeat elements of an Index.

View

slice_indexer() (start: object = None, end: object = None, step: object = None)

Compute slice indexer for input labels and step.

slice_locs() (start: object = None, end: object = None, step: object = None)

Compute slice locations for input labels.

View

sort() (*args, **kwargs) | (*args, **kwargs)

Return a sorted copy of the Index.

View

sortlevel() (level: object = None, ascending: object = True, sort_remaining: object = None, na_position: str = 'first')

Sort Index by the requested level.

View

Code Examples#

The following examples are extracted from the test suite.

dtype (test_index.py:40)
30# ==================== Test Functions ====================
31
32def test_constructor_and_properties():
33    """Test Index constructor and basic properties"""
34    f_print_header("Test: Constructor and Properties")
35
36    # Basic construction
37    idx = pandasCore.Index([1, 2, 3, 4, 5], name="test_idx")
38    ctx.assert_equal(5, idx.size, "size")
39    ctx.assert_equal("test_idx", idx.name, "name")
40    ctx.assert_equal("int64", idx.dtype, "dtype")
41    ctx.assert_false(idx.empty, "empty")
42    ctx.assert_true(idx.is_unique, "is_unique")
43    ctx.assert_true(idx.is_monotonic_increasing, "is_monotonic_increasing")
44    ctx.assert_false(idx.is_monotonic_decreasing, "is_monotonic_decreasing")
45    ctx.assert_equal(1, idx.ndim, "ndim")
46    ctx.assert_equal((5,), idx.shape, "shape")
47
48    # Duplicate values
49    idx_dup = pandasCore.Index([1, 2, 2, 3, 3, 3])
50    ctx.assert_false(idx_dup.is_unique, "is_unique with dups")
empty (test_index.py:41)
31def test_constructor_and_properties():
32    """Test Index constructor and basic properties"""
33    f_print_header("Test: Constructor and Properties")
34
35    # Basic construction
36    idx = pandasCore.Index([1, 2, 3, 4, 5], name="test_idx")
37    ctx.assert_equal(5, idx.size, "size")
38    ctx.assert_equal("test_idx", idx.name, "name")
39    ctx.assert_equal("int64", idx.dtype, "dtype")
40    ctx.assert_false(idx.empty, "empty")
41    ctx.assert_true(idx.is_unique, "is_unique")
42    ctx.assert_true(idx.is_monotonic_increasing, "is_monotonic_increasing")
43    ctx.assert_false(idx.is_monotonic_decreasing, "is_monotonic_decreasing")
44    ctx.assert_equal(1, idx.ndim, "ndim")
45    ctx.assert_equal((5,), idx.shape, "shape")
46
47    # Duplicate values
48    idx_dup = pandasCore.Index([1, 2, 2, 3, 3, 3])
49    ctx.assert_false(idx_dup.is_unique, "is_unique with dups")
50    ctx.assert_true(idx_dup.has_duplicates, "has_duplicates")
is_monotonic_decreasing (test_index.py:44)
34    f_print_header("Test: Constructor and Properties")
35
36    # Basic construction
37    idx = pandasCore.Index([1, 2, 3, 4, 5], name="test_idx")
38    ctx.assert_equal(5, idx.size, "size")
39    ctx.assert_equal("test_idx", idx.name, "name")
40    ctx.assert_equal("int64", idx.dtype, "dtype")
41    ctx.assert_false(idx.empty, "empty")
42    ctx.assert_true(idx.is_unique, "is_unique")
43    ctx.assert_true(idx.is_monotonic_increasing, "is_monotonic_increasing")
44    ctx.assert_false(idx.is_monotonic_decreasing, "is_monotonic_decreasing")
45    ctx.assert_equal(1, idx.ndim, "ndim")
46    ctx.assert_equal((5,), idx.shape, "shape")
47
48    # Duplicate values
49    idx_dup = pandasCore.Index([1, 2, 2, 3, 3, 3])
50    ctx.assert_false(idx_dup.is_unique, "is_unique with dups")
51    ctx.assert_true(idx_dup.has_duplicates, "has_duplicates")
52
53
54def test_copy():
is_monotonic_increasing (test_example.py:185)
175            return False
176
177        # Check is_unique
178        if idx.is_unique:
179            f_print_success("is_unique is True")
180        else:
181            f_print_error("is_unique should be True")
182            return False
183
184        # Check is_monotonic_increasing
185        if idx.is_monotonic_increasing:
186            f_print_success("is_monotonic_increasing is True")
187        else:
188            f_print_error("is_monotonic_increasing should be True")
189            return False
190
191        # Check len
192        if len(idx) == 5:
193            f_print_success("len(idx) is 5")
194        else:
195            f_print_error(f"len(idx) is {len(idx)}, expected 5")
is_unique (test_example.py:178)
168            return False
169
170        # Check name
171        if idx.name == "test_index":
172            f_print_success(f"Name is correct: {idx.name}")
173        else:
174            f_print_error(f"Name is wrong: {idx.name}, expected 'test_index'")
175            return False
176
177        # Check is_unique
178        if idx.is_unique:
179            f_print_success("is_unique is True")
180        else:
181            f_print_error("is_unique should be True")
182            return False
183
184        # Check is_monotonic_increasing
185        if idx.is_monotonic_increasing:
186            f_print_success("is_monotonic_increasing is True")
187        else:
188            f_print_error("is_monotonic_increasing should be True")
name (test_example.py:171)
161        f_print_success("Created Index from list")
162
163        # Check size
164        if idx.size == 5:
165            f_print_success(f"Size is correct: {idx.size}")
166        else:
167            f_print_error(f"Size is wrong: {idx.size}, expected 5")
168            return False
169
170        # Check name
171        if idx.name == "test_index":
172            f_print_success(f"Name is correct: {idx.name}")
173        else:
174            f_print_error(f"Name is wrong: {idx.name}, expected 'test_index'")
175            return False
176
177        # Check is_unique
178        if idx.is_unique:
179            f_print_success("is_unique is True")
180        else:
181            f_print_error("is_unique should be True")
ndim (test_index.py:45)
35    # Basic construction
36    idx = pandasCore.Index([1, 2, 3, 4, 5], name="test_idx")
37    ctx.assert_equal(5, idx.size, "size")
38    ctx.assert_equal("test_idx", idx.name, "name")
39    ctx.assert_equal("int64", idx.dtype, "dtype")
40    ctx.assert_false(idx.empty, "empty")
41    ctx.assert_true(idx.is_unique, "is_unique")
42    ctx.assert_true(idx.is_monotonic_increasing, "is_monotonic_increasing")
43    ctx.assert_false(idx.is_monotonic_decreasing, "is_monotonic_decreasing")
44    ctx.assert_equal(1, idx.ndim, "ndim")
45    ctx.assert_equal((5,), idx.shape, "shape")
46
47    # Duplicate values
48    idx_dup = pandasCore.Index([1, 2, 2, 3, 3, 3])
49    ctx.assert_false(idx_dup.is_unique, "is_unique with dups")
50    ctx.assert_true(idx_dup.has_duplicates, "has_duplicates")
51
52
53def test_copy():
54    """Test copy method"""
nlevels (test_index.py:773)
763    ctx.assert_list_equal([1, 2, 3], result.tolist(), "infer_objects")
764
765
766def test_nlevels():
767    """Test nlevels property"""
768    f_print_header("Test: nlevels")
769
770    idx = pandasCore.Index([1, 2, 3])
771
772    ctx.assert_equal(1, idx.nlevels, "nlevels")
773
774
775def f_main():
776    """Main test function"""
777    f_print_header("Index Phase 1 & 2: Core, Set Operations, Reshaping, Conversion Tests")
778
779    # Run all tests
780    test_functions = [
781        # Phase 1: Core & Set Operations
782        test_constructor_and_properties,
shape (test_index.py:46)
36    # Basic construction
37    idx = pandasCore.Index([1, 2, 3, 4, 5], name="test_idx")
38    ctx.assert_equal(5, idx.size, "size")
39    ctx.assert_equal("test_idx", idx.name, "name")
40    ctx.assert_equal("int64", idx.dtype, "dtype")
41    ctx.assert_false(idx.empty, "empty")
42    ctx.assert_true(idx.is_unique, "is_unique")
43    ctx.assert_true(idx.is_monotonic_increasing, "is_monotonic_increasing")
44    ctx.assert_false(idx.is_monotonic_decreasing, "is_monotonic_decreasing")
45    ctx.assert_equal(1, idx.ndim, "ndim")
46    ctx.assert_equal((5,), idx.shape, "shape")
47
48    # Duplicate values
49    idx_dup = pandasCore.Index([1, 2, 2, 3, 3, 3])
50    ctx.assert_false(idx_dup.is_unique, "is_unique with dups")
51    ctx.assert_true(idx_dup.has_duplicates, "has_duplicates")
52
53
54def test_copy():
55    """Test copy method"""
56    f_print_header("Test: copy")
size (test_example.py:164)
154    """Test Index creation from list"""
155    f_print_header("Test: Index Creation")
156
157    try:
158        # Create Index from list
159        data = [10, 20, 30, 40, 50]
160        idx = pandasCore.Index(data, name="test_index")
161        f_print_success("Created Index from list")
162
163        # Check size
164        if idx.size == 5:
165            f_print_success(f"Size is correct: {idx.size}")
166        else:
167            f_print_error(f"Size is wrong: {idx.size}, expected 5")
168            return False
169
170        # Check name
171        if idx.name == "test_index":
172            f_print_success(f"Name is correct: {idx.name}")
173        else:
174            f_print_error(f"Name is wrong: {idx.name}, expected 'test_index'")
str (test_index_str_accessor.py:52)
42def test_string_index_str_accessor():
43    """Test StringIndex.str accessor works."""
44    print("Testing StringIndex.str accessor...")
45
46    # Create a StringIndex
47    idx = pandasCore.StringIndex(['hello', 'world', 'test'])
48    print(f"  Created StringIndex: {idx}")
49
50    # Access .str
51    str_methods = idx.str
52    print(f"  idx.str type: {type(str_methods)}")
53
54    # Test upper()
55    result = str_methods.upper()
56    print(f"  idx.str.upper() result: {result}")
57
58    # Verify result
59    result_list = result.tolist()
60    expected = ['HELLO', 'WORLD', 'TEST']
61    assert result_list == expected, f"Expected {expected}, got {result_list}"
__init__ (test_example.py:160)
150        return False
151
152
153def test_index_creation():
154    """Test Index creation from list"""
155    f_print_header("Test: Index Creation")
156
157    try:
158        # Create Index from list
159        data = [10, 20, 30, 40, 50]
160        idx = pandasCore.Index(data, name="test_index")
161        f_print_success("Created Index from list")
162
163        # Check size
164        if idx.size == 5:
165            f_print_success(f"Size is correct: {idx.size}")
166        else:
167            f_print_error(f"Size is wrong: {idx.size}, expected 5")
168            return False
169
170        # Check name
take (test_index.py:405)
395    ctx.assert_equal(1, start, "slice_locs start")
396    ctx.assert_equal(4, stop, "slice_locs stop")
397
398
399def test_take():
400    """Test take method"""
401    f_print_header("Test: take")
402
403    idx = pandasCore.Index([10, 20, 30, 40])
404    result = idx.take([0, 2])
405
406    ctx.assert_list_equal([10, 30], result.tolist(), "take")
407
408
409def test_insert():
410    """Test insert method"""
411    f_print_header("Test: insert")
412
413    idx = pandasCore.Index([1, 2, 4])
414    result = idx.insert(2, 3)
drop (test_index.py:495)
485    ctx.assert_list_equal([1, 2, 3], result, "to_list")
486
487
488# ==================== Phase 2: Reshaping, Conversion & Testing ====================
489
490def test_drop():
491    """Test drop method"""
492    f_print_header("Test: drop")
493
494    idx = pandasCore.Index([1, 2, 3, 4, 5])
495    result = idx.drop([2, 4])
496
497    ctx.assert_list_equal([1, 3, 5], result.tolist(), "drop")
498
499
500def test_get_level_values():
501    """Test get_level_values method"""
502    f_print_header("Test: get_level_values")
503
504    idx = pandasCore.Index([1, 2, 3], name="level0")
505    result = idx.get_level_values(0)
insert (test_index.py:415)
405    result = idx.take([0, 2])
406
407    ctx.assert_list_equal([10, 30], result.tolist(), "take")
408
409
410def test_insert():
411    """Test insert method"""
412    f_print_header("Test: insert")
413
414    idx = pandasCore.Index([1, 2, 4])
415    result = idx.insert(2, 3)
416
417    ctx.assert_list_equal([1, 2, 3, 4], result.tolist(), "insert")
418
419
420def test_delete():
421    """Test delete method"""
422    f_print_header("Test: delete")
423
424    idx = pandasCore.Index([1, 2, 3, 4])
425    result = idx.delete(1)
reindex (test_index.py:516)
506    ctx.assert_list_equal([1, 2, 3], result.tolist(), "get_level_values")
507
508
509def test_reindex():
510    """Test reindex method"""
511    f_print_header("Test: reindex")
512
513    idx = pandasCore.Index([1, 2, 3])
514    target = pandasCore.Index([1, 3, 5])
515    new_idx, indexer = idx.reindex(target)
516
517    ctx.assert_list_equal([1, 3, 5], new_idx.tolist(), "reindex new_idx")
518    ctx.assert_list_equal([0, 2, -1], indexer, "reindex indexer")
519
520
521def test_sortlevel():
522    """Test sortlevel method"""
523    f_print_header("Test: sortlevel")
524
525    idx = pandasCore.Index([3, 1, 2])
rename (test_index.py:70)
60    ctx.assert_list_equal(idx.tolist(), idx_copy.tolist(), "copy values")
61    ctx.assert_equal(idx.name, idx_copy.name, "copy name")
62
63
64def test_rename():
65    """Test rename method"""
66    f_print_header("Test: rename")
67
68    idx = pandasCore.Index([1, 2, 3], name="old_name")
69    idx_new = idx.rename("new_name")
70
71    ctx.assert_equal("new_name", idx_new.name, "rename")
72    ctx.assert_equal("old_name", idx.name, "original unchanged")
73
74
75def test_set_names():
76    """Test set_names method"""
77    f_print_header("Test: set_names")
78
79    idx = pandasCore.Index([1, 2, 3], name="old")
set_names (test_index.py:81)
71    ctx.assert_equal("new_name", idx_new.name, "rename")
72    ctx.assert_equal("old_name", idx.name, "original unchanged")
73
74
75def test_set_names():
76    """Test set_names method"""
77    f_print_header("Test: set_names")
78
79    idx = pandasCore.Index([1, 2, 3], name="old")
80    idx_new = idx.set_names("new")
81
82    ctx.assert_equal("new", idx_new.name, "set_names")
83
84
85def test_map():
86    """Test map method"""
87    f_print_header("Test: map")
88
89    idx = pandasCore.Index([1, 2, 3])
90    idx_mapped = idx.map(lambda x: x * 2)
dropna (test_index.py:111)
101    idx_filled = idx.fillna(0)
102
103    ctx.assert_list_equal([1, 2, 3], idx_filled.tolist(), "fillna (int64)")
104
105
106def test_dropna():
107    """Test dropna method (for int64, essentially a no-op)"""
108    f_print_header("Test: dropna")
109
110    idx = pandasCore.Index([1, 2, 3])
111    idx_dropped = idx.dropna()
112
113    ctx.assert_list_equal([1, 2, 3], idx_dropped.tolist(), "dropna (int64)")
114
115
116def test_isna_notna():
117    """Test isna, notna, isnull, notnull methods"""
118    f_print_header("Test: isna/notna")
119
120    idx = pandasCore.Index([1, 2, 3])
fillna (test_index.py:101)
 91    idx_mapped = idx.map(lambda x: x * 2)
 92
 93    ctx.assert_list_equal([2, 4, 6], idx_mapped.tolist(), "map")
 94
 95
 96def test_fillna():
 97    """Test fillna method (for int64, essentially a no-op)"""
 98    f_print_header("Test: fillna")
 99
100    idx = pandasCore.Index([1, 2, 3])
101    idx_filled = idx.fillna(0)
102
103    ctx.assert_list_equal([1, 2, 3], idx_filled.tolist(), "fillna (int64)")
104
105
106def test_dropna():
107    """Test dropna method (for int64, essentially a no-op)"""
108    f_print_header("Test: dropna")
109
110    idx = pandasCore.Index([1, 2, 3])
111    idx_dropped = idx.dropna()
isna (test_index.py:123)
113    ctx.assert_list_equal([1, 2, 3], idx_dropped.tolist(), "dropna (int64)")
114
115
116def test_isna_notna():
117    """Test isna, notna, isnull, notnull methods"""
118    f_print_header("Test: isna/notna")
119
120    idx = pandasCore.Index([1, 2, 3])
121
122    # For int64, isna should return all False
123    isna_result = list(idx.isna())
124    ctx.assert_list_equal([False, False, False], isna_result, "isna (int64)")
125
126    notna_result = list(idx.notna())
127    ctx.assert_list_equal([True, True, True], notna_result, "notna (int64)")
128
129    # Test aliases
130    isnull_result = list(idx.isnull())
131    ctx.assert_list_equal([False, False, False], isnull_result, "isnull (int64)")
132
133    notnull_result = list(idx.notnull())
isnull (test_index.py:130)
120    idx = pandasCore.Index([1, 2, 3])
121
122    # For int64, isna should return all False
123    isna_result = list(idx.isna())
124    ctx.assert_list_equal([False, False, False], isna_result, "isna (int64)")
125
126    notna_result = list(idx.notna())
127    ctx.assert_list_equal([True, True, True], notna_result, "notna (int64)")
128
129    # Test aliases
130    isnull_result = list(idx.isnull())
131    ctx.assert_list_equal([False, False, False], isnull_result, "isnull (int64)")
132
133    notnull_result = list(idx.notnull())
134    ctx.assert_list_equal([True, True, True], notnull_result, "notnull (int64)")
135
136
137def test_drop_duplicates():
138    """Test drop_duplicates method"""
139    f_print_header("Test: drop_duplicates")
notna (test_index.py:126)
116def test_isna_notna():
117    """Test isna, notna, isnull, notnull methods"""
118    f_print_header("Test: isna/notna")
119
120    idx = pandasCore.Index([1, 2, 3])
121
122    # For int64, isna should return all False
123    isna_result = list(idx.isna())
124    ctx.assert_list_equal([False, False, False], isna_result, "isna (int64)")
125
126    notna_result = list(idx.notna())
127    ctx.assert_list_equal([True, True, True], notna_result, "notna (int64)")
128
129    # Test aliases
130    isnull_result = list(idx.isnull())
131    ctx.assert_list_equal([False, False, False], isnull_result, "isnull (int64)")
132
133    notnull_result = list(idx.notnull())
134    ctx.assert_list_equal([True, True, True], notnull_result, "notnull (int64)")
notnull (test_index.py:133)
123    isna_result = list(idx.isna())
124    ctx.assert_list_equal([False, False, False], isna_result, "isna (int64)")
125
126    notna_result = list(idx.notna())
127    ctx.assert_list_equal([True, True, True], notna_result, "notna (int64)")
128
129    # Test aliases
130    isnull_result = list(idx.isnull())
131    ctx.assert_list_equal([False, False, False], isnull_result, "isnull (int64)")
132
133    notnull_result = list(idx.notnull())
134    ctx.assert_list_equal([True, True, True], notnull_result, "notnull (int64)")
135
136
137def test_drop_duplicates():
138    """Test drop_duplicates method"""
139    f_print_header("Test: drop_duplicates")
140
141    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
142
143    # keep='first' (default)
max (test_index.py:214)
204    ctx.assert_equal(3, uniques.size, "factorize uniques size")
205
206
207def test_min_max():
208    """Test min and max methods"""
209    f_print_header("Test: min/max")
210
211    idx = pandasCore.Index([3, 1, 4, 1, 5, 9, 2, 6])
212
213    ctx.assert_equal(1, idx.min(), "min")
214    ctx.assert_equal(9, idx.max(), "max")
215
216
217def test_argmin_argmax():
218    """Test argmin and argmax methods"""
219    f_print_header("Test: argmin/argmax")
220
221    idx = pandasCore.Index([3, 1, 4, 1, 5, 9, 2, 6])
222
223    ctx.assert_equal(1, idx.argmin(), "argmin")  # First occurrence of min (1) is at index 1
224    ctx.assert_equal(5, idx.argmax(), "argmax")  # Max (9) is at index 5
min (test_index.py:213)
203    # Verify uniques
204    ctx.assert_equal(3, uniques.size, "factorize uniques size")
205
206
207def test_min_max():
208    """Test min and max methods"""
209    f_print_header("Test: min/max")
210
211    idx = pandasCore.Index([3, 1, 4, 1, 5, 9, 2, 6])
212
213    ctx.assert_equal(1, idx.min(), "min")
214    ctx.assert_equal(9, idx.max(), "max")
215
216
217def test_argmin_argmax():
218    """Test argmin and argmax methods"""
219    f_print_header("Test: argmin/argmax")
220
221    idx = pandasCore.Index([3, 1, 4, 1, 5, 9, 2, 6])
222
223    ctx.assert_equal(1, idx.argmin(), "argmin")  # First occurrence of min (1) is at index 1
nunique (test_index.py:178)
168    ctx.assert_list_equal([1, 2, 3], result.tolist(), "unique")
169
170
171def test_nunique():
172    """Test nunique method"""
173    f_print_header("Test: nunique")
174
175    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
176
177    ctx.assert_equal(3, idx.nunique(), "nunique")
178
179
180def test_value_counts():
181    """Test value_counts method"""
182    f_print_header("Test: value_counts")
183
184    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
185    result = idx.value_counts()
186
187    # Should return dict {3: 3, 2: 2, 1: 1} (sorted by count descending)
value_counts (test_index.py:186)
176    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
177
178    ctx.assert_equal(3, idx.nunique(), "nunique")
179
180
181def test_value_counts():
182    """Test value_counts method"""
183    f_print_header("Test: value_counts")
184
185    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
186    result = idx.value_counts()
187
188    # Should return dict {3: 3, 2: 2, 1: 1} (sorted by count descending)
189    ctx.assert_equal(3, result[3], "value_counts 3")
190    ctx.assert_equal(2, result[2], "value_counts 2")
191    ctx.assert_equal(1, result[1], "value_counts 1")
192
193
194def test_factorize():
195    """Test factorize method"""
196    f_print_header("Test: factorize")
groupby (test_index.py:593)
583    idx_some_nonzero = pandasCore.Index([0, 1, 0])
584    ctx.assert_true(idx_some_nonzero.any(), "any True")
585
586
587def test_groupby():
588    """Test groupby method"""
589    f_print_header("Test: groupby")
590
591    idx = pandasCore.Index([10, 20, 30, 40])
592    groups = idx.groupby([1, 1, 2, 2])
593
594    ctx.assert_list_equal([0, 1], groups[1], "groupby group 1")
595    ctx.assert_list_equal([2, 3], groups[2], "groupby group 2")
596
597
598def test_memory_usage():
599    """Test memory_usage method"""
600    f_print_header("Test: memory_usage")
601
602    idx = pandasCore.Index([1, 2, 3])
map (test_index.py:91)
 81    idx_new = idx.set_names("new")
 82
 83    ctx.assert_equal("new", idx_new.name, "set_names")
 84
 85
 86def test_map():
 87    """Test map method"""
 88    f_print_header("Test: map")
 89
 90    idx = pandasCore.Index([1, 2, 3])
 91    idx_mapped = idx.map(lambda x: x * 2)
 92
 93    ctx.assert_list_equal([2, 4, 6], idx_mapped.tolist(), "map")
 94
 95
 96def test_fillna():
 97    """Test fillna method (for int64, essentially a no-op)"""
 98    f_print_header("Test: fillna")
 99
100    idx = pandasCore.Index([1, 2, 3])
101    idx_filled = idx.fillna(0)
argsort (test_index.py:232)
222    ctx.assert_equal(1, idx.argmin(), "argmin")  # First occurrence of min (1) is at index 1
223    ctx.assert_equal(5, idx.argmax(), "argmax")  # Max (9) is at index 5
224
225
226def test_argsort():
227    """Test argsort method"""
228    f_print_header("Test: argsort")
229
230    idx = pandasCore.Index([3, 1, 2])
231    result = list(idx.argsort())
232
233    ctx.assert_list_equal([1, 2, 0], result, "argsort")
234
235
236def test_searchsorted():
237    """Test searchsorted method"""
238    f_print_header("Test: searchsorted")
239
240    idx = pandasCore.Index([1, 2, 3, 4, 5])
searchsorted (test_index.py:244)
234    ctx.assert_list_equal([1, 2, 0], result, "argsort")
235
236
237def test_searchsorted():
238    """Test searchsorted method"""
239    f_print_header("Test: searchsorted")
240
241    idx = pandasCore.Index([1, 2, 3, 4, 5])
242
243    # Single value returns scalar
244    result = idx.searchsorted(3)
245    ctx.assert_equal(2, result, "searchsorted single")
246
247
248def test_append():
249    """Test append method"""
250    f_print_header("Test: append")
251
252    idx1 = pandasCore.Index([1, 2, 3])
253    idx2 = pandasCore.Index([4, 5])
254    result = idx1.append(idx2)
sort_values (test_index.py:459)
449    ctx.assert_true(idx1.identical(idx2), "identical True")
450    ctx.assert_false(idx1.identical(idx3), "identical False (different name)")
451
452
453def test_sort_values():
454    """Test sort_values method"""
455    f_print_header("Test: sort_values")
456
457    idx = pandasCore.Index([3, 1, 2])
458    result = idx.sort_values()
459
460    ctx.assert_list_equal([1, 2, 3], result.tolist(), "sort_values")
461
462    # Descending
463    result_desc = idx.sort_values(ascending=False)
464    ctx.assert_list_equal([3, 2, 1], result_desc.tolist(), "sort_values descending")
465
466
467def test_contains():
468    """Test __contains__ method"""
to_frame (test_index.py:690)
680    result = idx.item()
681
682    ctx.assert_equal(42, result, "item")
683
684
685def test_to_frame():
686    """Test to_frame method"""
687    f_print_header("Test: to_frame")
688
689    idx = pandasCore.Index([1, 2, 3], name="values")
690    frame_data = idx.to_frame()
691
692    ctx.assert_equal("values", frame_data["column_name"], "to_frame column_name")
693    ctx.assert_list_equal([1, 2, 3], frame_data["values"], "to_frame values")
694
695
696def test_to_series():
697    """Test to_series method"""
698    f_print_header("Test: to_series")
699
700    idx = pandasCore.Index([1, 2, 3], name="values")
transpose (test_index.py:722)
712    result = idx.to_flat_index()
713
714    ctx.assert_list_equal([1, 2, 3], result.tolist(), "to_flat_index")
715
716
717def test_transpose():
718    """Test transpose method"""
719    f_print_header("Test: transpose")
720
721    idx = pandasCore.Index([1, 2, 3])
722    result = idx.transpose()
723
724    ctx.assert_list_equal([1, 2, 3], result.tolist(), "transpose")
725
726
727def test_repeat():
728    """Test repeat method"""
729    f_print_header("Test: repeat")
730
731    idx = pandasCore.Index([1, 2, 3])
732    result = idx.repeat(2)
asof (test_index.py:616)
606    ctx.assert_true(mem > 0, "memory_usage positive")
607
608
609def test_asof():
610    """Test asof method"""
611    f_print_header("Test: asof")
612
613    idx = pandasCore.Index([1, 3, 5, 7])
614
615    # Exact match
616    result = idx.asof(3)
617    ctx.assert_equal(3, result, "asof exact")
618
619    # Lookup between values
620    result = idx.asof(4)
621    ctx.assert_equal(3, result, "asof between")
622
623
624def test_asof_locs():
625    """Test asof_locs method"""
626    f_print_header("Test: asof_locs")
diff (test_index.py:561)
551    result = idx.round(2)
552
553    ctx.assert_list_equal([1, 2, 3], result.tolist(), "round (int64 no-op)")
554
555
556def test_diff():
557    """Test diff method"""
558    f_print_header("Test: diff")
559
560    idx = pandasCore.Index([1, 3, 6, 10])
561    result = idx.diff()
562
563    ctx.assert_list_equal([0, 2, 3, 4], result.tolist(), "diff")
564
565
566def test_all():
567    """Test all method"""
568    f_print_header("Test: all")
569
570    idx_all_true = pandasCore.Index([1, 2, 3])
571    ctx.assert_true(idx_all_true.all(), "all True")
shift (test_index.py:538)
528    ctx.assert_list_equal([1, 2, 3], sorted_idx.tolist(), "sortlevel sorted")
529    ctx.assert_list_equal([1, 2, 0], indexer, "sortlevel indexer")
530
531
532def test_shift():
533    """Test shift method"""
534    f_print_header("Test: shift")
535
536    idx = pandasCore.Index([1, 2, 3, 4])
537    result = idx.shift(2)
538
539    ctx.assert_list_equal([0, 0, 1, 2], result.tolist(), "shift positive")
540
541    result_neg = idx.shift(-1)
542    ctx.assert_list_equal([2, 3, 4, 0], result_neg.tolist(), "shift negative")
543
544
545def test_round():
546    """Test round method (no-op for int64)"""
547    f_print_header("Test: round")
to_flat_index (test_index.py:712)
702    ctx.assert_list_equal([1, 2, 3], series_data["values"], "to_series values")
703    ctx.assert_equal("values", series_data["name"], "to_series name")
704
705
706def test_to_flat_index():
707    """Test to_flat_index method"""
708    f_print_header("Test: to_flat_index")
709
710    idx = pandasCore.Index([1, 2, 3])
711    result = idx.to_flat_index()
712
713    ctx.assert_list_equal([1, 2, 3], result.tolist(), "to_flat_index")
714
715
716def test_transpose():
717    """Test transpose method"""
718    f_print_header("Test: transpose")
719
720    idx = pandasCore.Index([1, 2, 3])
721    result = idx.transpose()
to_list (test_index.py:483)
473    ctx.assert_true(2 in idx, "__contains__ True")
474    ctx.assert_false(5 in idx, "__contains__ False")
475
476
477def test_to_list():
478    """Test to_list method"""
479    f_print_header("Test: to_list")
480
481    idx = pandasCore.Index([1, 2, 3])
482    result = idx.to_list()
483
484    ctx.assert_list_equal([1, 2, 3], result, "to_list")
485
486
487# ==================== Phase 2: Reshaping, Conversion & Testing ====================
488
489def test_drop():
490    """Test drop method"""
491    f_print_header("Test: drop")
to_series (test_index.py:701)
691    ctx.assert_equal("values", frame_data["column_name"], "to_frame column_name")
692    ctx.assert_list_equal([1, 2, 3], frame_data["values"], "to_frame values")
693
694
695def test_to_series():
696    """Test to_series method"""
697    f_print_header("Test: to_series")
698
699    idx = pandasCore.Index([1, 2, 3], name="values")
700    series_data = idx.to_series()
701
702    ctx.assert_list_equal([1, 2, 3], series_data["values"], "to_series values")
703    ctx.assert_equal("values", series_data["name"], "to_series name")
704
705
706def test_to_flat_index():
707    """Test to_flat_index method"""
708    f_print_header("Test: to_flat_index")
709
710    idx = pandasCore.Index([1, 2, 3])
tolist (test_index.py:61)
51    ctx.assert_true(idx_dup.has_duplicates, "has_duplicates")
52
53
54def test_copy():
55    """Test copy method"""
56    f_print_header("Test: copy")
57
58    idx = pandasCore.Index([1, 2, 3], name="original")
59    idx_copy = idx.copy()
60
61    ctx.assert_list_equal(idx.tolist(), idx_copy.tolist(), "copy values")
62    ctx.assert_equal(idx.name, idx_copy.name, "copy name")
63
64
65def test_rename():
66    """Test rename method"""
67    f_print_header("Test: rename")
68
69    idx = pandasCore.Index([1, 2, 3], name="old_name")
70    idx_new = idx.rename("new_name")
copy (test_index.py:59)
49    idx_dup = pandasCore.Index([1, 2, 2, 3, 3, 3])
50    ctx.assert_false(idx_dup.is_unique, "is_unique with dups")
51    ctx.assert_true(idx_dup.has_duplicates, "has_duplicates")
52
53
54def test_copy():
55    """Test copy method"""
56    f_print_header("Test: copy")
57
58    idx = pandasCore.Index([1, 2, 3], name="original")
59    idx_copy = idx.copy()
60
61    ctx.assert_list_equal(idx.tolist(), idx_copy.tolist(), "copy values")
62    ctx.assert_equal(idx.name, idx_copy.name, "copy name")
63
64
65def test_rename():
66    """Test rename method"""
67    f_print_header("Test: rename")
68
69    idx = pandasCore.Index([1, 2, 3], name="old_name")
infer_objects (test_index.py:762)
752    result = idx.putmask([False, True, False, True], 0)
753
754    ctx.assert_list_equal([1, 0, 3, 0], result.tolist(), "putmask")
755
756
757def test_infer_objects():
758    """Test infer_objects method"""
759    f_print_header("Test: infer_objects")
760
761    idx = pandasCore.Index([1, 2, 3])
762    result = idx.infer_objects()
763
764    ctx.assert_list_equal([1, 2, 3], result.tolist(), "infer_objects")
765
766
767def test_nlevels():
768    """Test nlevels property"""
769    f_print_header("Test: nlevels")
770
771    idx = pandasCore.Index([1, 2, 3])
view (test_index_methods.py:57)
47    tests_run += 1
48    idx = pandasCore.PeriodIndex(['2023-03', '2023-01', '2023-02'], freq='M')
49    result = idx.sort()
50    assert len(result) == 3, f"Expected 3 elements, got {len(result)}"
51
52def test_periodindex_view():
53    """Test PeriodIndex.view"""
54    global tests_run
55    tests_run += 1
56    idx = pandasCore.PeriodIndex(['2023-01', '2023-02'], freq='M')
57    result = idx.view()
58    assert len(result) == 2, f"Expected 2 elements, got {len(result)}"
59
60def test_intervalindex_infer_objects():
61    """Test IntervalIndex.infer_objects"""
62    global tests_run
63    tests_run += 1
64    idx = pandasCore.IntervalIndex.from_breaks([0, 1, 2, 3])
65    result = idx.infer_objects()
66    assert len(result) == 3, f"Expected 3 elements, got {len(result)}"
drop_duplicates (test_index.py:144)
134    ctx.assert_list_equal([True, True, True], notnull_result, "notnull (int64)")
135
136
137def test_drop_duplicates():
138    """Test drop_duplicates method"""
139    f_print_header("Test: drop_duplicates")
140
141    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
142
143    # keep='first' (default)
144    result = idx.drop_duplicates()
145    ctx.assert_list_equal([1, 2, 3], result.tolist(), "drop_duplicates (first)")
146
147    # keep='last'
148    result_last = idx.drop_duplicates(keep="last")
149    ctx.assert_list_equal([1, 2, 3], result_last.tolist(), "drop_duplicates (last)")
150
151
152def test_duplicated():
153    """Test duplicated method"""
154    f_print_header("Test: duplicated")
duplicated (test_index.py:158)
148    result_last = idx.drop_duplicates(keep="last")
149    ctx.assert_list_equal([1, 2, 3], result_last.tolist(), "drop_duplicates (last)")
150
151
152def test_duplicated():
153    """Test duplicated method"""
154    f_print_header("Test: duplicated")
155
156    idx = pandasCore.Index([1, 2, 2, 3])
157
158    result = list(idx.duplicated())
159    ctx.assert_list_equal([False, False, True, False], result, "duplicated")
160
161
162def test_unique():
163    """Test unique method"""
164    f_print_header("Test: unique")
165
166    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
167    result = idx.unique()
isin (test_index.py:331)
321    result_set = set(result.tolist())
322    expected_set = {2, 3}
323    ctx.assert_equal(expected_set, result_set, "join (inner)")
324
325
326def test_isin():
327    """Test isin method"""
328    f_print_header("Test: isin")
329
330    idx = pandasCore.Index([1, 2, 3, 4])
331    result = list(idx.isin([2, 4]))
332
333    ctx.assert_list_equal([False, True, False, True], result, "isin")
334
335
336def test_get_loc():
337    """Test get_loc method"""
338    f_print_header("Test: get_loc")
339
340    idx = pandasCore.Index([10, 20, 30, 40])
unique (test_index.py:167)
157    result = list(idx.duplicated())
158    ctx.assert_list_equal([False, False, True, False], result, "duplicated")
159
160
161def test_unique():
162    """Test unique method"""
163    f_print_header("Test: unique")
164
165    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
166    result = idx.unique()
167
168    ctx.assert_list_equal([1, 2, 3], result.tolist(), "unique")
169
170
171def test_nunique():
172    """Test nunique method"""
173    f_print_header("Test: nunique")
174
175    idx = pandasCore.Index([1, 2, 2, 3, 3, 3])
round (test_index.py:551)
541    result_neg = idx.shift(-1)
542    ctx.assert_list_equal([2, 3, 4, 0], result_neg.tolist(), "shift negative")
543
544
545def test_round():
546    """Test round method (no-op for int64)"""
547    f_print_header("Test: round")
548
549    idx = pandasCore.Index([1, 2, 3])
550    result = idx.round(2)
551
552    ctx.assert_list_equal([1, 2, 3], result.tolist(), "round (int64 no-op)")
553
554
555def test_diff():
556    """Test diff method"""
557    f_print_header("Test: diff")
558
559    idx = pandasCore.Index([1, 3, 6, 10])
560    result = idx.diff()
argmax (test_index.py:224)
214    ctx.assert_equal(9, idx.max(), "max")
215
216
217def test_argmin_argmax():
218    """Test argmin and argmax methods"""
219    f_print_header("Test: argmin/argmax")
220
221    idx = pandasCore.Index([3, 1, 4, 1, 5, 9, 2, 6])
222
223    ctx.assert_equal(1, idx.argmin(), "argmin")  # First occurrence of min (1) is at index 1
224    ctx.assert_equal(5, idx.argmax(), "argmax")  # Max (9) is at index 5
225
226
227def test_argsort():
228    """Test argsort method"""
229    f_print_header("Test: argsort")
230
231    idx = pandasCore.Index([3, 1, 2])
232    result = list(idx.argsort())
233
234    ctx.assert_list_equal([1, 2, 0], result, "argsort")
argmin (test_index.py:223)
213    ctx.assert_equal(1, idx.min(), "min")
214    ctx.assert_equal(9, idx.max(), "max")
215
216
217def test_argmin_argmax():
218    """Test argmin and argmax methods"""
219    f_print_header("Test: argmin/argmax")
220
221    idx = pandasCore.Index([3, 1, 4, 1, 5, 9, 2, 6])
222
223    ctx.assert_equal(1, idx.argmin(), "argmin")  # First occurrence of min (1) is at index 1
224    ctx.assert_equal(5, idx.argmax(), "argmax")  # Max (9) is at index 5
225
226
227def test_argsort():
228    """Test argsort method"""
229    f_print_header("Test: argsort")
230
231    idx = pandasCore.Index([3, 1, 2])
232    result = list(idx.argsort())
asof_locs (test_index.py:630)
620    result = idx.asof(4)
621    ctx.assert_equal(3, result, "asof between")
622
623
624def test_asof_locs():
625    """Test asof_locs method"""
626    f_print_header("Test: asof_locs")
627
628    idx = pandasCore.Index([1, 3, 5, 7])
629    where = pandasCore.Index([2, 4, 6])
630    result = idx.asof_locs(where)
631
632    ctx.assert_equal(3, len(result), "asof_locs length")
633
634
635def test_get_slice_bound():
636    """Test get_slice_bound method"""
637    f_print_header("Test: get_slice_bound")
638
639    idx = pandasCore.Index([1, 2, 3, 4, 5])
delete (test_index.py:425)
415    result = idx.insert(2, 3)
416
417    ctx.assert_list_equal([1, 2, 3, 4], result.tolist(), "insert")
418
419
420def test_delete():
421    """Test delete method"""
422    f_print_header("Test: delete")
423
424    idx = pandasCore.Index([1, 2, 3, 4])
425    result = idx.delete(1)
426
427    ctx.assert_list_equal([1, 3, 4], result.tolist(), "delete")
428
429
430def test_equals():
431    """Test equals method"""
432    f_print_header("Test: equals")
433
434    idx1 = pandasCore.Index([1, 2, 3])
435    idx2 = pandasCore.Index([1, 2, 3])
factorize (test_index.py:199)
189    ctx.assert_equal(3, result[3], "value_counts 3")
190    ctx.assert_equal(2, result[2], "value_counts 2")
191    ctx.assert_equal(1, result[1], "value_counts 1")
192
193
194def test_factorize():
195    """Test factorize method"""
196    f_print_header("Test: factorize")
197
198    idx = pandasCore.Index([3, 1, 2, 3, 1])
199    codes, uniques = idx.factorize()
200
201    # Verify codes length matches
202    ctx.assert_equal(5, len(list(codes)), "factorize codes length")
203    # Verify uniques
204    ctx.assert_equal(3, uniques.size, "factorize uniques size")
205
206
207def test_min_max():
208    """Test min and max methods"""
209    f_print_header("Test: min/max")
format (test_index.py:742)
732    result = idx.repeat(2)
733
734    ctx.assert_list_equal([1, 1, 2, 2, 3, 3], result.tolist(), "repeat scalar")
735
736
737def test_format():
738    """Test format method"""
739    f_print_header("Test: format")
740
741    idx = pandasCore.Index([1, 2, 3])
742    result = idx.format()
743
744    ctx.assert_list_equal(["1", "2", "3"], result, "format")
745
746
747def test_putmask():
748    """Test putmask method"""
749    f_print_header("Test: putmask")
750
751    idx = pandasCore.Index([1, 2, 3, 4])
752    result = idx.putmask([False, True, False, True], 0)
get_indexer (test_index.py:362)
352        ctx.tests_run += 1
353        ctx.tests_passed += 1
354
355
356def test_get_indexer():
357    """Test get_indexer method"""
358    f_print_header("Test: get_indexer")
359
360    idx = pandasCore.Index([1, 2, 3])
361    target = pandasCore.Index([1, 3, 5])
362    result = list(idx.get_indexer(target))
363
364    ctx.assert_list_equal([0, 2, -1], result, "get_indexer")
365
366
367def test_get_indexer_for():
368    """Test get_indexer_for method"""
369    f_print_header("Test: get_indexer_for")
370
371    idx = pandasCore.Index([1, 2, 3])
372    result = list(idx.get_indexer_for([1, 3]))
get_indexer_for (test_index.py:372)
362    result = list(idx.get_indexer(target))
363
364    ctx.assert_list_equal([0, 2, -1], result, "get_indexer")
365
366
367def test_get_indexer_for():
368    """Test get_indexer_for method"""
369    f_print_header("Test: get_indexer_for")
370
371    idx = pandasCore.Index([1, 2, 3])
372    result = list(idx.get_indexer_for([1, 3]))
373
374    ctx.assert_list_equal([0, 2], result, "get_indexer_for")
375
376
377def test_get_indexer_non_unique():
378    """Test get_indexer_non_unique method"""
379    f_print_header("Test: get_indexer_non_unique")
380
381    idx = pandasCore.Index([1, 2, 2, 3])
382    target = pandasCore.Index([2, 5])
get_indexer_non_unique (test_index.py:383)
373    ctx.assert_list_equal([0, 2], result, "get_indexer_for")
374
375
376def test_get_indexer_non_unique():
377    """Test get_indexer_non_unique method"""
378    f_print_header("Test: get_indexer_non_unique")
379
380    idx = pandasCore.Index([1, 2, 2, 3])
381    target = pandasCore.Index([2, 5])
382    indexer, missing = idx.get_indexer_non_unique(target)
383
384    # Should find indices for 2 and mark 5 as missing
385    ctx.assert_true(len(list(indexer)) > 0, "get_indexer_non_unique has indexer")
386
387
388def test_slice_locs():
389    """Test slice_locs method"""
390    f_print_header("Test: slice_locs")
391
392    idx = pandasCore.Index([1, 2, 3, 4, 5])
get_level_values (test_index.py:505)
495    result = idx.drop([2, 4])
496
497    ctx.assert_list_equal([1, 3, 5], result.tolist(), "drop")
498
499
500def test_get_level_values():
501    """Test get_level_values method"""
502    f_print_header("Test: get_level_values")
503
504    idx = pandasCore.Index([1, 2, 3], name="level0")
505    result = idx.get_level_values(0)
506
507    ctx.assert_list_equal([1, 2, 3], result.tolist(), "get_level_values")
508
509
510def test_reindex():
511    """Test reindex method"""
512    f_print_header("Test: reindex")
513
514    idx = pandasCore.Index([1, 2, 3])
515    target = pandasCore.Index([1, 3, 5])
get_loc (test_index.py:342)
332    ctx.assert_list_equal([False, True, False, True], result, "isin")
333
334
335def test_get_loc():
336    """Test get_loc method"""
337    f_print_header("Test: get_loc")
338
339    idx = pandasCore.Index([10, 20, 30, 40])
340
341    ctx.assert_equal(1, idx.get_loc(20), "get_loc")
342
343    # Test KeyError for missing key
344    try:
345        idx.get_loc(99)
346        f_print_error("get_loc should raise KeyError for missing key")
347        ctx.tests_run += 1
348        ctx.tests_failed += 1
349    except KeyError:
350        f_print_success("get_loc raises KeyError for missing key: PASS")
351        ctx.tests_run += 1
get_slice_bound (test_index.py:641)
631    ctx.assert_equal(3, len(result), "asof_locs length")
632
633
634def test_get_slice_bound():
635    """Test get_slice_bound method"""
636    f_print_header("Test: get_slice_bound")
637
638    idx = pandasCore.Index([1, 2, 3, 4, 5])
639
640    left_bound = idx.get_slice_bound(3, "left")
641    ctx.assert_equal(2, left_bound, "get_slice_bound left")
642
643    right_bound = idx.get_slice_bound(3, "right")
644    ctx.assert_equal(3, right_bound, "get_slice_bound right")
645
646
647def test_type_checks():
648    """Test type checking methods"""
649    f_print_header("Test: type checking methods")
holds_integer (test_index.py:654)
644    right_bound = idx.get_slice_bound(3, "right")
645    ctx.assert_equal(3, right_bound, "get_slice_bound right")
646
647
648def test_type_checks():
649    """Test type checking methods"""
650    f_print_header("Test: type checking methods")
651
652    idx = pandasCore.Index([1, 2, 3])
653
654    ctx.assert_true(idx.holds_integer(), "holds_integer")
655    ctx.assert_true(idx.is_integer(), "is_integer")
656    ctx.assert_true(idx.is_numeric(), "is_numeric")
657    ctx.assert_false(idx.is_boolean(), "is_boolean")
658    ctx.assert_false(idx.is_floating(), "is_floating")
659    ctx.assert_false(idx.is_categorical(), "is_categorical")
660    ctx.assert_false(idx.is_interval(), "is_interval")
661    ctx.assert_false(idx.is_object(), "is_object")
662
663
664def test_is_():
item (test_index.py:680)
670    # Different objects
671    ctx.assert_false(idx1.is_(idx2), "is_ different objects")
672
673
674def test_item():
675    """Test item method"""
676    f_print_header("Test: item")
677
678    idx = pandasCore.Index([42])
679    result = idx.item()
680
681    ctx.assert_equal(42, result, "item")
682
683
684def test_to_frame():
685    """Test to_frame method"""
686    f_print_header("Test: to_frame")
687
688    idx = pandasCore.Index([1, 2, 3], name="values")
689    frame_data = idx.to_frame()
memory_usage (test_index.py:604)
594    ctx.assert_list_equal([0, 1], groups[1], "groupby group 1")
595    ctx.assert_list_equal([2, 3], groups[2], "groupby group 2")
596
597
598def test_memory_usage():
599    """Test memory_usage method"""
600    f_print_header("Test: memory_usage")
601
602    idx = pandasCore.Index([1, 2, 3])
603    mem = idx.memory_usage()
604
605    ctx.assert_true(mem > 0, "memory_usage positive")
606
607
608def test_asof():
609    """Test asof method"""
610    f_print_header("Test: asof")
611
612    idx = pandasCore.Index([1, 3, 5, 7])
putmask (test_index.py:752)
742    result = idx.format()
743
744    ctx.assert_list_equal(["1", "2", "3"], result, "format")
745
746
747def test_putmask():
748    """Test putmask method"""
749    f_print_header("Test: putmask")
750
751    idx = pandasCore.Index([1, 2, 3, 4])
752    result = idx.putmask([False, True, False, True], 0)
753
754    ctx.assert_list_equal([1, 0, 3, 0], result.tolist(), "putmask")
755
756
757def test_infer_objects():
758    """Test infer_objects method"""
759    f_print_header("Test: infer_objects")
760
761    idx = pandasCore.Index([1, 2, 3])
762    result = idx.infer_objects()
repeat (test_index.py:732)
722    result = idx.transpose()
723
724    ctx.assert_list_equal([1, 2, 3], result.tolist(), "transpose")
725
726
727def test_repeat():
728    """Test repeat method"""
729    f_print_header("Test: repeat")
730
731    idx = pandasCore.Index([1, 2, 3])
732    result = idx.repeat(2)
733
734    ctx.assert_list_equal([1, 1, 2, 2, 3, 3], result.tolist(), "repeat scalar")
735
736
737def test_format():
738    """Test format method"""
739    f_print_header("Test: format")
740
741    idx = pandasCore.Index([1, 2, 3])
742    result = idx.format()
slice_locs (test_index.py:394)
384    # Should find indices for 2 and mark 5 as missing
385    ctx.assert_true(len(list(indexer)) > 0, "get_indexer_non_unique has indexer")
386
387
388def test_slice_locs():
389    """Test slice_locs method"""
390    f_print_header("Test: slice_locs")
391
392    idx = pandasCore.Index([1, 2, 3, 4, 5])
393    start, stop = idx.slice_locs(2, 4)
394
395    ctx.assert_equal(1, start, "slice_locs start")
396    ctx.assert_equal(4, stop, "slice_locs stop")
397
398
399def test_take():
400    """Test take method"""
401    f_print_header("Test: take")
402
403    idx = pandasCore.Index([10, 20, 30, 40])
sort (test_index_methods.py:16)
 6import pandasCore
 7
 8tests_run = 0
 9
10def test_index_sort():
11    """Test Index.sort"""
12    global tests_run
13    tests_run += 1
14    idx = pandasCore.Index([3, 1, 2])
15    result = idx.sort()
16    assert len(result) == 3, f"Expected 3 elements, got {len(result)}"
17
18def test_timedeltaindex_sortlevel():
19    """Test TimedeltaIndex.sortlevel"""
20    global tests_run
21    tests_run += 1
22    idx = pandasCore.TimedeltaIndex(['1 day', '2 days', '1 hour'])
23    result = idx.sortlevel()
24    # Returns tuple of (sorted_index, indexer)
25    assert len(result) == 2, f"Expected tuple of 2, got {len(result)}"
sortlevel (test_index.py:527)
517    ctx.assert_list_equal([1, 3, 5], new_idx.tolist(), "reindex new_idx")
518    ctx.assert_list_equal([0, 2, -1], indexer, "reindex indexer")
519
520
521def test_sortlevel():
522    """Test sortlevel method"""
523    f_print_header("Test: sortlevel")
524
525    idx = pandasCore.Index([3, 1, 2])
526    sorted_idx, indexer = idx.sortlevel()
527
528    ctx.assert_list_equal([1, 2, 3], sorted_idx.tolist(), "sortlevel sorted")
529    ctx.assert_list_equal([1, 2, 0], indexer, "sortlevel indexer")
530
531
532def test_shift():
533    """Test shift method"""
534    f_print_header("Test: shift")
535
536    idx = pandasCore.Index([1, 2, 3, 4])