-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Fix Series constructor when copy=True #15128
BUG: Fix Series constructor when copy=True #15128
Conversation
y = pd.Series(x, copy=True, dtype=float) | ||
|
||
# copy=True maintains original data in Series | ||
self.assertTrue(x.equals(y)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use tm.assert_series_equal
to compare the series.
def test_constructor_copy(self): | ||
# GH15125 | ||
# test dtype parameter has no side effects on copy=True | ||
x = Series(np.array([1.])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do this in a loop, testing the for both of these as input to the Series.
[1.], np.array([1.])
@@ -362,3 +362,4 @@ Bug Fixes | |||
|
|||
|
|||
- Bug in ``pd.read_csv()`` for the C engine where ``usecols`` were being indexed incorrectly with ``parse_dates`` (:issue:`14792`) | |||
- Bug in ``Series`` constructor when both ``copy=True`` and ``dtype`` argument is provided (:issue:`15125`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is -> are
minor comments. ping when updated / green. |
221af87
to
f7af1c2
Compare
|
||
# changes to origin of copy does not affect the copy | ||
x[0] = 2. | ||
with self.assertRaises(AssertionError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you would want to
self.assertFalse(x.equals(y))
using assert_series_equal
to test non-equality in anti-pattern.
x[0] = 2. | ||
with self.assertRaises(AssertionError): | ||
tm.assert_series_equal(x, y) | ||
self.assertEqual(y[0], 1.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a self.assertEqual(x[0], 2.)
Updates Series constructor to include copy argument when dtype argument is also provided. Adds tests for copy parameter. xref pandas-dev#15125
f7af1c2
to
7b0c959
Compare
Current coverage is 85.53% (diff: 100%)@@ master #15128 diff @@
==========================================
Files 145 145
Lines 51288 51288
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 43872 43871 -1
- Misses 7416 7417 +1
Partials 0 0
|
Thanks for pointing out the anti-pattern, @jreback. All green now. Let me know if you see any other changes. |
thanks! |
Updates Series constructor to include copy argument when dtype argument is also provided. closes pandas-dev#15125 Author: Rouz Azari <[email protected]> Closes pandas-dev#15128 from rouzazari/series_dtype_param_no_side_effects_when_copy_true and squashes the following commits: 7b0c959 [Rouz Azari] BUG: Fix Series constructor when copy=True
Updates Series constructor to include copy argument when dtype argument
is also provided. Adds tests for copy parameter.
xref #15125
git diff upstream/master | flake8 --diff