Skip to content

Commit abe48c9

Browse files
committed
address review
1 parent 78a2d84 commit abe48c9

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

doc/source/whatsnew/v0.23.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ Timezones
896896
- Bug in :func:`Timestamp.tz_localize` where localizing a timestamp near the minimum or maximum valid values could overflow and return a timestamp with an incorrect nanosecond value (:issue:`12677`)
897897
- Bug when iterating over :class:`DatetimeIndex` that was localized with fixed timezone offset that rounded nanosecond precision to microseconds (:issue:`19603`)
898898
- Bug in :func:`DataFrame.diff` that raised an ``IndexError`` with tz-aware values (:issue:`18578`)
899-
- Bug in :func:`melt` that coverted tz-aware dtypes to tz-naive (:issue:`15785`)
899+
- Bug in :func:`melt` that converted tz-aware dtypes to tz-naive (:issue:`15785`)
900900

901901
Offsets
902902
^^^^^^^

pandas/core/reshape/melt.py

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def melt(frame, id_vars=None, value_vars=None, var_name=None,
7474
for col in id_vars:
7575
id_data = frame.pop(col)
7676
if is_extension_type(id_data):
77-
# Preserve pandas dtype by not converting to a numpy array
7877
id_data = concat([id_data] * K, ignore_index=True)
7978
else:
8079
id_data = np.tile(id_data.values, K)

pandas/tests/reshape/test_melt.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,16 @@ def test_multiindex(self):
214214

215215
@pytest.mark.parametrize("col", [
216216
pd.Series(pd.date_range('2010', periods=5, tz='US/Pacific')),
217-
pd.Series(["a", "b", "c", "a", "d"], dtype="category")])
218-
@pytest.mark.parametrize("pandas_dtype_value", [True, False])
219-
def test_pandas_dtypes_id_var(self, col, pandas_dtype_value):
217+
pd.Series(["a", "b", "c", "a", "d"], dtype="category"),
218+
pd.Series([0, 1, 0, 0, 0])])
219+
def test_pandas_dtypes(self, col):
220220
# GH 15785
221-
# Pandas dtype in the id
222221
df = DataFrame({'klass': range(5),
223222
'col': col,
224-
'attr1': [1, 0, 0, 0, 0]})
225-
if pandas_dtype_value:
226-
# Pandas dtype in the value as well
227-
df['attr2'] = col
228-
expected_value = pd.concat([pd.Series([1, 0, 0, 0, 0]), col],
229-
ignore_index=True)
230-
else:
231-
df['attr2'] = [0, 1, 0, 0, 0]
232-
expected_value = [1, 0, 0, 0, 0] + [0, 1, 0, 0, 0]
223+
'attr1': [1, 0, 0, 0, 0],
224+
'attr2': col})
225+
expected_value = pd.concat([pd.Series([1, 0, 0, 0, 0]), col],
226+
ignore_index=True)
233227
result = melt(df, id_vars=['klass', 'col'], var_name='attribute',
234228
value_name='value')
235229
expected = DataFrame({0: list(range(5)) * 2,

0 commit comments

Comments
 (0)