Fixed: Pandas4Warning "For backward compatibility, 'str' dtypes are included by select_dtypes when 'object' dtype is specified" in MLflow log_table
pytest passed all 31 tests of a project that logs tables to MLflow, then printed a warnings summary: Pandas4Warning: For backward compatibility, 'str' dtypes are included by select_dtypes when 'object' dtype is specified. It comes from one line inside mlflow.log_table() meeting pandas 3's new text type, and it changes nothing about the tables you log. One filterwarnings line hides exactly this warning until an MLflow release stops raising it.
What I Was Doing
I had just added mlflow.log_table() to the house price project of the MLflow series, to save the model's feature importances as a table with every run. The table has a text column, feature, and a number column, importance. The versions: MLflow 3.18.0, pandas 3.1.1, pytest 9.2.0 and Python 3.15.2.
The project's tests train small models and log real runs to a temporary SQLite tracking database. I ran them:
uv run pytest
What I Expected
31 passed, and nothing else to read.
What I Got
============================================ test session starts =============================================
platform darwin -- Python 3.15.2, pytest-9.2.0, pluggy-1.7.0
rootdir: /Users/you/source/dewiride-house-price-prediction
configfile: pyproject.toml
testpaths: tests
plugins: anyio-4.16.0
collected 31 items
tests/test_config.py ..... [ 16%]
tests/test_curve.py ... [ 25%]
tests/test_data.py .... [ 38%]
tests/test_datasets.py ... [ 48%]
tests/test_plots.py . [ 51%]
tests/test_reports.py .. [ 58%]
tests/test_train.py ............. [100%]
============================================== warnings summary ==============================================
tests/test_train.py::test_a_run_logs_params_metrics_tags_and_the_chart
tests/test_train.py::test_a_run_records_its_datasets_and_files
tests/test_train.py::test_validation_scores_are_logged_at_every_step
/Users/you/source/dewiride-house-price-prediction/.venv/lib/python3.15/site-packages/mlflow/tracking/client.py:3509: Pandas4Warning: For backward compatibility, 'str' dtypes are included by select_dtypes when 'object' dtype is specified. This behavior is deprecated and will be removed in a future version. Explicitly pass 'str' to `include` to select them, or to `exclude` to remove them and silence this warning.
See https://pandas.pydata.org/docs/dev/user_guide/migration.html#string-migration-select-dtypes for details on how to write code that works with pandas 2 and 3.
if len(data.select_dtypes(include=["object"]).columns) > 0:
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================= 31 passed, 3 warnings in 5.39s =======================================

All tests passed. pytest listed the same warning under the three tests that run a full training, which are the three that call mlflow.log_table().
What I Checked
Whose code it points at. Line 3509 of mlflow/tracking/client.py is inside MLflow's own log_table(). Before saving a table, it looks for columns that hold pictures, so it can store them as image files:
# Check if the column is a `PIL.Image.Image` or `mlflow.Image` object
# and save filepath
if len(data.select_dtypes(include=["object"]).columns) > 0:
Pictures can only live in columns of pandas' general object type, so MLflow asks pandas for those columns.
What pandas 3 changed. pandas 3 stores text in a new dedicated type, str, instead of object. The feature column is text, so its type is str. pandas still hands str columns back when code asks for object, for backward compatibility, and warns that it will stop doing so. Its migration guide explains: "For selecting string columns with select_dtypes() in a pandas 2.x and 3.x compatible way, it is not possible to use "str"", and suggests selecting both object and "string" instead.
What changes when pandas stops. Only text columns are affected. MLflow's check is looking for pictures, which stay in object columns, so when str columns stop being included the check simply skips the feature column. The table you log stays the same.
Why only pytest showed it. Pandas4Warning is a kind of DeprecationWarning:
uv run python -c "import inspect, pandas.errors as e; print([c.__name__ for c in inspect.getmro(e.Pandas4Warning)])"
['Pandas4Warning', 'PandasDeprecationWarning', 'PandasChangeWarning', 'DeprecationWarning', 'Warning', 'Exception', 'BaseException', 'object']
Python hides deprecation warnings that come from inside a library unless you ask for them. pytest's documentation: "By default pytest will display DeprecationWarning and PendingDeprecationWarning warnings from user code and third-party libraries, as recommended by PEP 565." The same project's training runs never printed it.
MLflow's code and issue tracker. On November 19, 2026, MLflow 3.18.0 was still the newest release, the same line was still on MLflow's main branch, and no issue in MLflow's tracker mentioned Pandas4Warning.
Why It Happens
mlflow.log_table() asks pandas for object columns to find pictures. Under pandas 3, a text column has the str type, which pandas still includes in that answer with a Pandas4Warning about the future. The warning is a DeprecationWarning, so a normal run hides it and pytest shows it.
The Fix
Tell pytest to ignore this one warning, but only when it comes from MLflow's log_table(). In pyproject.toml, add a line to the filterwarnings list of the [tool.pytest] table:
[tool.pytest]
testpaths = ["tests"]
filterwarnings = [
# MLflow 3.18.0 still uses lazy="noload", which SQLAlchemy 2.1 deprecates. The fix
# (mlflow/mlflow#27467) ships after 3.18.0: delete this line once you upgrade MLflow.
'ignore:The ``noload`` loader strategy is deprecated:sqlalchemy.exc.SADeprecationWarning',
# mlflow.log_table() looks for image columns with select_dtypes(include=["object"]), which
# pandas 3 warns about for text columns. Delete this line once an MLflow release stops it.
"ignore:For backward compatibility, 'str' dtypes are included by select_dtypes:pandas.errors.Pandas4Warning:mlflow.tracking.client",
]

The first entry is the project's earlier fix for another MLflow warning, SADeprecationWarning "The noload loader strategy is deprecated". Leave it out if your project doesn't have it. The new entry reads action:message:category:module:
ignoreis what pytest does with a matching warning.- The message is a regular expression that the start of the warning must match:
For backward compatibility, 'str' dtypes are included by select_dtypes. - The category is the warning's class,
pandas.errors.Pandas4Warning. - The module limits the filter to warnings raised from
mlflow.tracking.client. If your own code ever triggers the same warning, pytest still shows it, so you can fix your code. - Double quotes around the entry make it a TOML basic string, because the message itself contains single quotes.
- The comment says when to delete the line, so it doesn't outlive the problem.
After the Fix
uv run pytest
Uninstalled 1 package in 4ms
Installed 1 package in 3ms
============================================ test session starts =============================================
platform darwin -- Python 3.15.2, pytest-9.2.0, pluggy-1.7.0
rootdir: /Users/you/source/dewiride-house-price-prediction
configfile: pyproject.toml
testpaths: tests
plugins: anyio-4.16.0
collected 31 items
tests/test_config.py ..... [ 16%]
tests/test_curve.py ... [ 25%]
tests/test_data.py .... [ 38%]
tests/test_datasets.py ... [ 48%]
tests/test_plots.py . [ 51%]
tests/test_reports.py .. [ 58%]
tests/test_train.py ............. [100%]
============================================= 31 passed in 5.23s =============================================

The first two lines are uv reinstalling the project, because pyproject.toml changed. Then 31 passed, with no warnings summary.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Ignoring every DeprecationWarning | Warnings about your own code disappear too | Filter by message, category and module |
Converting your text columns to object to avoid the warning | Your table loses pandas 3's text type for no gain | Leave the data alone and filter the one warning |
| Writing the entry in single quotes | TOML ends the string at the first ' inside the message | Use double quotes, as above |
| Leaving the filter in after upgrading MLflow | It may hide the warning if it ever comes back | Delete it when a release stops raising it |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The warning still shows | The settings are in a table pytest doesn't read | Use [tool.pytest] on pytest 9, [tool.pytest.ini_options] before it |
pytest stops with ERROR: while parsing the following warning configuration: | A typo in the category's dotted name, such as Pandas4Warnin | Copy pandas.errors.Pandas4Warning exactly |
| The same warning appears from your own file | Your code calls select_dtypes(include=["object"]) on text | Pass include=["object", "string"], as the pandas migration guide shows |
FAQ
Are the logged tables wrong?
No. The check only looks for picture columns, and the table is written the same way with or without the warning. All 31 tests passed, including one that reads a logged table back.
Why don't I see it when I train normally?
Because it's a DeprecationWarning from inside a library, which Python hides by default. pytest shows those on purpose, so problems surface in tests first.
Will a newer pandas turn this into an error?
The warning says the behavior "will be removed in a future version": include=["object"] will stop returning text columns. For log_table() that means the picture check skips them, which is what it needs anyway.
Conclusion
Pandas4Warning: For backward compatibility, 'str' dtypes are included by select_dtypes comes from a picture check inside MLflow 3.18.0's log_table(), which asks pandas 3 for object columns while your table's text column has the new str type. The table is unaffected. One filterwarnings entry, limited to the warning's message, class and MLflow's module, keeps pytest's output clean until an MLflow release changes that line.
Additional Resources
- pandas migration guide: select_dtypes — the string type change and how to select text columns in pandas 2 and 3.
- mlflow.log_table — MLflow's reference for the function.
- How to capture warnings — pytest's
filterwarningsand how it treats deprecation warnings.
