sadpandajoe commented on code in PR #40456:
URL: https://github.com/apache/superset/pull/40456#discussion_r3462473762
##########
tests/unit_tests/pandas_postprocessing/test_histogram.py:
##########
@@ -207,3 +207,13 @@ def test_histogram_with_no_groupby_and_all_null_values():
result = histogram(data_with_no_groupby_and_all_nulls, "a", [], bins)
assert result.empty
+
+
+def test_histogram_no_setting_with_copy_warning():
+ import warnings
+ from pandas.errors import SettingWithCopyWarning
+ source = DataFrame({"a": [1, 2, None, 4, 5], "b": list(range(5))})
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ histogram(source.loc[source["b"] >= 0], "a", [], 3)
Review Comment:
I think this needs to prove the regression by using an actual sliced input.
Since `source["b"] >= 0` selects every row, this doesn’t really exercise the
slice/view case that would warn if the `.copy()` in `histogram.py` were
removed. Can we make the fixture a real subset and verify locally that this
test fails when `.copy()` is temporarily removed?
```suggestion
source = DataFrame({"a": [1, 2, None, 4, 5], "b": list(range(5))})
sliced = source[source["b"] > 0]
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
histogram(sliced, "a", [], 3)
```suggestion
source = DataFrame({"a": [1, 2, None, 4, 5], "b": list(range(5))})
sliced = source[source["b"] >= 0]
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
histogram(sliced, "a", [], 3)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]