Skip to content

Commit 7e566ec

Browse files
committed
unitstrippedwarning
1 parent 77d8df8 commit 7e566ec

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

pint_pandas/pint_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ def __array__(self, dtype=None, copy=False):
685685

686686
def _to_array_of_quantity(self, copy=False):
687687
qtys = [self._Q(item, self._dtype.units) for item in self._data]
688-
return np.array(qtys, dtype="object", copy=copy)
688+
with warnings.catch_warnings(record=True):
689+
return np.array(qtys, dtype="object", copy=copy)
689690

690691
def searchsorted(self, value, side="left", sorter=None):
691692
"""

pint_pandas/testsuite/test_pandas_extensiontests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def test_unstack(self, data, index, obj):
579579

580580

581581
class TestSetitem(base.BaseSetitemTests):
582-
@pytest.mark.xfail(run=True, reason="excess warnings, needs debugging")
582+
# @pytest.mark.xfail(run=True, reason="excess warnings, needs debugging")
583583
def test_setitem_frame_2d_values(self, data):
584584
# GH#44514
585585
df = pd.DataFrame({"A": data})

test.bak

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)