Skip to content
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

Conversation

rouzazari
Copy link
Contributor

Updates Series constructor to include copy argument when dtype argument
is also provided. Adds tests for copy parameter.

xref #15125

y = pd.Series(x, copy=True, dtype=float)

# copy=True maintains original data in Series
self.assertTrue(x.equals(y))
Copy link
Contributor

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.]))
Copy link
Contributor

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.])

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Jan 13, 2017
@@ -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`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is -> are

@jreback
Copy link
Contributor

jreback commented Jan 13, 2017

minor comments. ping when updated / green.

@rouzazari rouzazari force-pushed the series_dtype_param_no_side_effects_when_copy_true branch from 221af87 to f7af1c2 Compare January 13, 2017 20:20

# changes to origin of copy does not affect the copy
x[0] = 2.
with self.assertRaises(AssertionError):
Copy link
Contributor

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.)
Copy link
Contributor

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
@rouzazari rouzazari force-pushed the series_dtype_param_no_side_effects_when_copy_true branch from f7af1c2 to 7b0c959 Compare January 14, 2017 23:16
@codecov-io
Copy link

codecov-io commented Jan 14, 2017

Current coverage is 85.53% (diff: 100%)

Merging #15128 into master will decrease coverage by <.01%

@@             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          

Powered by Codecov. Last update 1f82f18...7b0c959

@rouzazari
Copy link
Contributor Author

rouzazari commented Jan 15, 2017

Thanks for pointing out the anti-pattern, @jreback. All green now. Let me know if you see any other changes.

@jreback jreback added this to the 0.20.0 milestone Jan 15, 2017
@jreback
Copy link
Contributor

jreback commented Jan 15, 2017

thanks!

@jreback jreback closed this in 0e219d7 Jan 15, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series constructor ignores copy=True when dtype agrees
3 participants