|
| 1 | +import pandas as pd |
| 2 | +import pint |
| 3 | +import pint_pandas |
| 4 | +import numpy as np |
| 5 | +u = ureg =pint.UnitRegistry() |
| 6 | +pint_pandas.PintType.ureg = u |
| 7 | +from pint_pandas import PintArray, PintType |
| 8 | + |
| 9 | +import pdb |
| 10 | + |
| 11 | +from pint_pandas.testsuite.test_pandas_extensiontests import TestSetitem |
| 12 | +self = TestSetitem() |
| 13 | + |
| 14 | +_all_arithmetic_operators = [ |
| 15 | + "__add__", |
| 16 | + "__radd__", |
| 17 | + "__sub__", |
| 18 | + "__rsub__", |
| 19 | + "__mul__", |
| 20 | + "__rmul__", |
| 21 | + "__floordiv__", |
| 22 | + "__rfloordiv__", |
| 23 | + "__truediv__", |
| 24 | + "__rtruediv__", |
| 25 | + "__pow__", |
| 26 | + "__rpow__", |
| 27 | + "__mod__", |
| 28 | + "__rmod__", |
| 29 | +] |
| 30 | +import pandas._testing as tm |
| 31 | + |
| 32 | +all_arithmetic_operators = "__radd__" |
| 33 | + |
| 34 | +data = PintArray.from_1darray_quantity(np.arange(start=1.0, stop=101.0) * ureg.nm) |
| 35 | + |
| 36 | +# GH#44514 |
| 37 | +df = pd.DataFrame({"A": data}) |
| 38 | + |
| 39 | +# These dtypes have non-broken implementations of _can_hold_element |
| 40 | +has_can_hold_element = False |
| 41 | + |
| 42 | +# Avoiding using_array_manager fixture |
| 43 | +# https://github.com/pandas-dev/pandas/pull/44514#discussion_r754002410 |
| 44 | +using_array_manager = isinstance(df._mgr, pd.core.internals.ArrayManager) |
| 45 | + |
| 46 | +blk_data = df._mgr.arrays[0] |
| 47 | + |
| 48 | +orig = df.copy() |
| 49 | + |
| 50 | +msg = "will attempt to set the values inplace instead" |
| 51 | +warn = None |
| 52 | +if has_can_hold_element and not isinstance(data.dtype, PandasDtype): |
| 53 | + # PandasDtype excluded because it isn't *really* supported. |
| 54 | + warn = FutureWarning |
| 55 | + |
| 56 | +with tm.assert_produces_warning(warn, match=msg): |
| 57 | + df.iloc[:] = df |
| 58 | +self.assert_frame_equal(df, orig) |
| 59 | + |
| 60 | +df.iloc[:-1] = df.iloc[:-1] |
| 61 | +self.assert_frame_equal(df, orig) |
| 62 | + |
| 63 | +#if isinstance(data.dtype, DatetimeTZDtype): |
| 64 | +# # no warning bc df.values casts to object dtype |
| 65 | +# warn = None |
| 66 | +#df.iloc[:] = df.values |
| 67 | +print(df, df.dtypes) |
| 68 | +df.iloc[:] = df.values |
| 69 | +print(df, df.dtypes) |
| 70 | +#self.assert_frame_equal(df, orig) |
0 commit comments