Skip to content

Commit 2006292

Browse files
authored
FIX-#7292: Prepare Modin code to NumPy 2.0 (#7293)
Signed-off-by: Anatoly Myachev <[email protected]>
1 parent 31771d7 commit 2006292

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

modin/core/dataframe/pandas/dataframe/utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ def add_missing_categories_to_groupby(
868868
### At this stage we want to get a fill_value for missing categorical values
869869
if is_udf_agg and isinstance(total_index, pandas.MultiIndex):
870870
# if grouping on multiple columns and aggregating with an UDF, then the
871-
# fill value is always `np.NaN`
872-
missing_values = pandas.DataFrame({0: [np.NaN]})
871+
# fill value is always `np.nan`
872+
missing_values = pandas.DataFrame({0: [np.nan]})
873873
else:
874874
# In case of a udf aggregation we're forced to run the operator against each
875875
# missing category, as in theory it can return different results for each
@@ -903,8 +903,8 @@ def add_missing_categories_to_groupby(
903903
).columns
904904
else:
905905
# HACK: If the aggregation has failed, the result would be empty. Assuming the
906-
# fill value to be `np.NaN` here (this may not always be correct!!!)
907-
fill_value = np.NaN if len(missing_values) == 0 else missing_values.iloc[0, 0]
906+
# fill value to be `np.nan` here (this may not always be correct!!!)
907+
fill_value = np.nan if len(missing_values) == 0 else missing_values.iloc[0, 0]
908908
missing_values = pandas.DataFrame(
909909
fill_value, index=missing_index, columns=combined_cols
910910
)

modin/core/storage_formats/pandas/query_compiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ def map_func(df, resample_kwargs=resample_kwargs): # pragma: no cover
11051105
resample_kwargs = resample_kwargs.copy()
11061106
resample_kwargs["level"] = None
11071107
filler = pandas.DataFrame(
1108-
np.NaN, index=pandas.Index(timestamps), columns=df.columns
1108+
np.nan, index=pandas.Index(timestamps), columns=df.columns
11091109
)
11101110
df = pandas.concat([df, filler], copy=False)
11111111
if df_op is not None:

modin/numpy/arr.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ def floor_divide(
16221622
# the output.
16231623
result = (
16241624
result.replace(numpy.inf, 0)
1625-
.replace(numpy.NINF, 0)
1625+
.replace(-numpy.inf, 0)
16261626
.where(self._query_compiler.ne(0), 0)
16271627
)
16281628
return fix_dtypes_and_determine_return(
@@ -1644,7 +1644,7 @@ def floor_divide(
16441644
# the output.
16451645
result = (
16461646
result.replace(numpy.inf, 0)
1647-
.replace(numpy.NINF, 0)
1647+
.replace(-numpy.inf, 0)
16481648
.where(callee.ne(0), 0)
16491649
)
16501650
return fix_dtypes_and_determine_return(result, new_ndim, dtype, out, where)
@@ -1902,7 +1902,7 @@ def remainder(
19021902
if x2 == 0 and numpy.issubdtype(out_dtype, numpy.integer):
19031903
# NumPy's remainder by 0 works differently from pandas', so we need to fix
19041904
# the output.
1905-
result = result.replace(numpy.NaN, 0)
1905+
result = result.replace(numpy.nan, 0)
19061906
return fix_dtypes_and_determine_return(
19071907
result, self._ndim, dtype, out, where
19081908
)
@@ -1920,7 +1920,7 @@ def remainder(
19201920
if callee.eq(0).any() and numpy.issubdtype(out_dtype, numpy.integer):
19211921
# NumPy's floor_divide by 0 works differently from pandas', so we need to fix
19221922
# the output.
1923-
result = result.replace(numpy.NaN, 0)
1923+
result = result.replace(numpy.nan, 0)
19241924
return fix_dtypes_and_determine_return(result, new_ndim, dtype, out, where)
19251925

19261926
__mod__ = remainder

modin/pandas/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ def _setitem_with_new_columns(self, row_loc, col_loc, item):
844844
for i in range(len(common_label_loc)):
845845
if not common_label_loc[i]:
846846
columns = columns.insert(len(columns), col_loc[i])
847-
self.qc = self.qc.reindex(labels=columns, axis=1, fill_value=np.NaN)
847+
self.qc = self.qc.reindex(labels=columns, axis=1, fill_value=np.nan)
848848
self.df._update_inplace(new_query_compiler=self.qc)
849849
self._set_item_existing_loc(row_loc, np.array(col_loc), item)
850850

modin/tests/numpy/test_array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_array_where():
275275

276276
@pytest.mark.parametrize("method", ["argmax", "argmin"])
277277
def test_argmax_argmin(method):
278-
numpy_arr = numpy.array([[1, 2, 3], [4, 5, np.NaN]])
278+
numpy_arr = numpy.array([[1, 2, 3], [4, 5, np.nan]])
279279
modin_arr = np.array(numpy_arr)
280280
assert_scalar_or_array_equal(
281281
getattr(np, method)(modin_arr, axis=1),

modin/tests/pandas/dataframe/test_binary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_multi_level_comparison(data, op):
254254
pytest.param({}, {}, True, id="two_empty_dataframes"),
255255
pytest.param([[1]], [[0]], False, id="single_unequal_values"),
256256
pytest.param([[None]], [[None]], True, id="single_none_values"),
257-
pytest.param([[np.NaN]], [[np.NaN]], True, id="single_nan_values"),
257+
pytest.param([[np.nan]], [[np.nan]], True, id="single_nan_values"),
258258
pytest.param({1: [10]}, {1.0: [10]}, True, id="different_column_types"),
259259
pytest.param({1: [10]}, {2: [10]}, False, id="different_columns"),
260260
pytest.param(

modin/tests/pandas/dataframe/test_join_sort.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def test_sort_values_with_only_one_non_na_row_in_partition(ascending, na_positio
879879
np.random.rand(1000, 100), columns=[f"col {i}" for i in range(100)]
880880
)
881881
# Need to ensure that one of the partitions has all NA values except for one row
882-
pandas_df.iloc[340:] = np.NaN
882+
pandas_df.iloc[340:] = np.nan
883883
pandas_df.iloc[-1] = -4.0
884884
modin_df = pd.DataFrame(pandas_df)
885885
eval_general(

modin/tests/pandas/test_groupby.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ def test_simple_row_groupby(by, as_index, col1_category):
479479
pandas_df = pandas.DataFrame(
480480
{
481481
"col1": [0, 1, 2, 3],
482-
"col2": [4, 5, np.NaN, 7],
483-
"col3": [np.NaN, np.NaN, 12, 10],
482+
"col2": [4, 5, np.nan, 7],
483+
"col3": [np.nan, np.nan, 12, 10],
484484
"col4": [17, 13, 16, 15],
485485
"col5": [-4, -5, -6, -7],
486486
}
@@ -1850,8 +1850,8 @@ def test_shift_freq(groupby_axis, shift_axis, groupby_sort):
18501850
pandas_df = pandas.DataFrame(
18511851
{
18521852
"col1": [1, 0, 2, 3],
1853-
"col2": [4, 5, np.NaN, 7],
1854-
"col3": [np.NaN, np.NaN, 12, 10],
1853+
"col2": [4, 5, np.nan, 7],
1854+
"col3": [np.nan, np.nan, 12, 10],
18551855
"col4": [17, 13, 16, 15],
18561856
}
18571857
)

modin/tests/pandas/test_series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4008,11 +4008,11 @@ def test_str___getitem__(data, key):
40084008
# Test str operations
40094009
@pytest.mark.parametrize(
40104010
"others",
4011-
[["abC|DeF,Hik", "gSaf,qWer|Gre", "asd3,4sad|", np.NaN], None],
4011+
[["abC|DeF,Hik", "gSaf,qWer|Gre", "asd3,4sad|", np.nan], None],
40124012
ids=["list", "None"],
40134013
)
40144014
def test_str_cat(others):
4015-
data = ["abC|DeF,Hik", "gSaf,qWer|Gre", "asd3,4sad|", np.NaN]
4015+
data = ["abC|DeF,Hik", "gSaf,qWer|Gre", "asd3,4sad|", np.nan]
40164016
eval_general(*create_test_series(data), lambda s: s.str.cat(others=others))
40174017

40184018

@@ -4644,7 +4644,7 @@ def str_encode_decode_test_data() -> list[str]:
46444644
"234,3245.67",
46454645
"gSaf,qWer|Gre",
46464646
"asd3,4sad|",
4647-
np.NaN,
4647+
np.nan,
46484648
None,
46494649
# add a string that we can't encode in ascii, and whose utf-8 encoding
46504650
# we cannot decode in ascii

modin/tests/pandas/utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
(
8989
x
9090
if (j % 4 == 0 and i > NCOLS // 2) or (j != i and i <= NCOLS // 2)
91-
else np.NaN
91+
else np.nan
9292
)
9393
for j, x in enumerate(
9494
random_state.uniform(RAND_LOW, RAND_HIGH, size=(NROWS))
@@ -161,7 +161,7 @@
161161
for col in test_data["float_nan_data"]:
162162
for row in range(NROWS // 2):
163163
if row % 16 == 0:
164-
test_data["float_nan_data"][col][row] = np.NaN
164+
test_data["float_nan_data"][col][row] = np.nan
165165

166166
test_data_values = list(test_data.values())
167167
test_data_keys = list(test_data.keys())
@@ -226,8 +226,8 @@
226226

227227
test_data_diff_dtype = {
228228
"int_col": [-5, 2, 7, 16],
229-
"float_col": [np.NaN, -9.4, 10.1, np.NaN],
230-
"str_col": ["a", np.NaN, "c", "d"],
229+
"float_col": [np.nan, -9.4, 10.1, np.nan],
230+
"str_col": ["a", np.nan, "c", "d"],
231231
"bool_col": [False, True, True, False],
232232
}
233233

@@ -272,7 +272,7 @@
272272
"234,3245.67",
273273
"gSaf,qWer|Gre",
274274
"asd3,4sad|",
275-
np.NaN,
275+
np.nan,
276276
]
277277
}
278278

@@ -290,7 +290,7 @@
290290
string_sep_values = list(string_seperators.values())
291291
string_sep_keys = list(string_seperators.keys())
292292

293-
string_na_rep = {"None na_rep": None, "- na_rep": "-", "nan na_rep": np.NaN}
293+
string_na_rep = {"None na_rep": None, "- na_rep": "-", "nan na_rep": np.nan}
294294

295295
string_na_rep_values = list(string_na_rep.values())
296296
string_na_rep_keys = list(string_na_rep.keys())

0 commit comments

Comments
 (0)