Skip to content

pandas/deprecated-in-pandas-3

Rule deprecated-in-pandas-3
Pack pandas
Severity warning
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions every version

These names and arguments warn on pandas 3 and will stop working in a later release. Use the replacement that the example and the table show.

now = pd.Timestamp.utcnow()
now = pd.Timestamp.now("UTC")

The rule reports pd.set_option("mode.copy_on_write", True), copy=False, pd.Timestamp.utcnow(), pd.Timestamp.utcfromtimestamp(t), and the units "H" and "S" in pd.Timedelta("1H"), pd.to_timedelta(x, unit="H") and resample(offset="1H"). Each form warns on pandas 3.1.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The safe fix writes pd.Timestamp.now("UTC"), pd.Timestamp.fromtimestamp(t, "UTC"), "h" and "s" for the Timedelta units "H" and "S", and it drops copy=. The unsafe fix deletes the copy-on-write option line, because pd.get_option reads the value back, and drops copy= from astype.

The rule reports astype(copy=) only on a column taken by a label or on a value named like a frame, because NumPy's astype has the same keyword. Dropping copy= from astype is unsafe, because on a NumPy array astype(copy=False) can return the same array. The rule deletes the copy-on-write option line at the top level of a file and in a block that holds another statement. As the only statement of a block it reports the line without a fix, because the block would be empty.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

Timestamp.utcnow is deprecated. Write $PD.Timestamp.now("UTC"), which returns the same time.

Browse the other rules of the pandas pack.