В настоящее время я отслеживаю FutureWarnings, чтобы очистить существующий код. Чтобы молчать и включить в будущем поведение понижающего приведения в «replace», оно устарело и будет удалено в будущей версии, я использую pd.set_option("future.no_silent_downcasting", True).
Затем я останавливаюсь на следующем минимальном примере:
Код: Выделить всё
import pandas as pd
print(f"{pd.__version__=}") # '2.2.3'
# discard "Downcasting behavior in `replace`..."
pd.set_option("future.no_silent_downcasting", True)
# Raise en Exception on any Warning:
from warnings import warn, simplefilter
simplefilter('error') # raise on Warning
df0 = pd.DataFrame({"a": [True, True, False, True, False]})
df1 = pd.DataFrame({"a": [False, True]}, index=[2,4])
# First attempt:
# raise `FutureWarning: Setting an item of incompatible dtype is deprecated and will raise
# in a future error of pandas.
# Value '[True True False True True]' has dtype incompatible with bool, please explicitly cast to a compatible dtype first.`
df0.update(df1) # Raise a FutureWarning
# Second attempt
df0.update(df1.astype(df0.dtypes)) # Also raise the same FutureWarning
Подробнее здесь: https://stackoverflow.com/questions/792 ... ng-working
Мобильная версия